creating objects with web api, POST fails

Hi
I have a server (on Linux, running on Tomcat) with and empty dhis app running (version 2.14)

I would like to populate it with data (and metadata) using the web API.

I tried an example from the documentation:

I created a file called pi.xml:

<constant name="PI" xmlns="[http://dhis2.org/schema/dxf/2.0](http://dhis2.org/schema/dxf/2.0)  "> <value>3.14159265359</value> </constant>
and gave this command from my windows command line:

C:\>curl.exe -d @pi.xml "http://<my host name>:8080/dhis/api/constants" -H "Content-Type:application/xml" -u admin:district -v

The server responded with
<html><head><title>Apache Tomcat/7.0.52 (Debian) - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 405 - Request method 'POST' not supported</h1><HR size="1" noshade="noshade"><p><b>type</b>Status report</p><p><b>message</b> <u>Request method 'POST' not supported</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52 (Debian)</h3></body></html>

when I tried the same with https (instead of http), I got the reply:
C:\>curl.exe -d @pi.xml "https://<my host name>:8080/dhis/api/constants" - H "Content-Type:application/xml" -u admin:district -v * Hostname was NOT found in DNS cache * Trying <my host ip address>... * Connected to <my host name> (<my host ip adress>) port 8080 (#0) * schannel: SSL/TLS connection with <my host name> port 8080 (step 1/3)
* schannel: checking server certificate revocation * schannel: sending initial handshake data: sending 171 bytes... * schannel: sent initial handshake data: sent 171 bytes * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: failed to receive handshake, need more data * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: encrypted data buffer: offset 144 length 4096 * schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid * Closing connection 0 * schannel: shutting down SSL/TLS connection with <my host name> port 8080 * schannel: clear security context handle * schannel: clear credential handle curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

The same command (using https with my windows curl) was successful when sent to the dhis web site demo app

I am guessing that creating objects in dhis requires a secure connection and that my server does not currently support it. (or does not support the specific ssh protocol that curl uses?) 
Is this the problem or am I missing something?

Thanks,
Lavi

Hi Lavi,

the problem is the DHIS version - we implemented support for CRUD operations at the various end-points in version 2.15. Could you please update to 2.15 and try again?

dhis2.org/downloads

regards,

Lars

PS. we need to version our docs but haven’t gotten around to do it yet.

···

On Sun, Jun 29, 2014 at 1:08 PM, Lavi Shpigelman shpigi@gmail.com wrote:

Hi
I have a server (on Linux, running on Tomcat) with and empty dhis app running (version 2.14)

I would like to populate it with data (and metadata) using the web API.

I tried an example from the documentation:

I created a file called pi.xml:

<constant name="PI" xmlns="[http://dhis2.org/schema/dxf/2.0](http://dhis2.org/schema/dxf/2.0)  "> <value>3.14159265359</value> </constant>
and gave this command from my windows command line:

C:\>curl.exe -d @pi.xml "http://<my host name>:8080/dhis/api/constants" -H "Content-Type:application/xml" -u admin:district -v



The server responded with
<html><head><title>Apache Tomcat/7.0.52 (Debian) - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 405 - Request method 'POST' not supported</h1><HR size="1" noshade="noshade"><p><b>type</b>Status report</p><p><b>message</b> <u>Request method 'POST' not supported</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52 (Debian)</h3></body></html>



when I tried the same with https (instead of http), I got the reply:
C:\>curl.exe -d @pi.xml "https://<my host name>:8080/dhis/api/constants" - H "Content-Type:application/xml" -u admin:district -v * Hostname was NOT found in DNS cache * Trying <my host ip address>... * Connected to <my host name> (<my host ip adress>) port 8080 (#0) * schannel: SSL/TLS connection with <my host name> port 8080 (step 1/3)
* schannel: checking server certificate revocation * schannel: sending initial handshake data: sending 171 bytes... * schannel: sent initial handshake data: sent 171 bytes * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: failed to receive handshake, need more data * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: encrypted data buffer: offset 144 length 4096 * schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid * Closing connection 0 * schannel: shutting down SSL/TLS connection with <my host name> port 8080 * schannel: clear security context handle * schannel: clear credential handle curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

The same command (using https with my windows curl) was successful when sent to the dhis web site demo app

I am guessing that creating objects in dhis requires a secure connection and that my server does not currently support it. (or does not support the specific ssh protocol that curl uses?) 
Is this the problem or am I missing something?


Thanks,
Lavi

Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Thanks for the clarification, Lars !

The problem is that I would prefer to stay compatible with the version currently used by our collaborators which is actually 2.13.

I’m, guessing there must be a way to push data to this version.

Can you specify what it is (perhaps access to 2.13 documentation would help)?

Best regards,

Lavi

···

On Tue, Jul 1, 2014 at 3:25 PM, Lars Helge Øverland larshelge@gmail.com wrote:

Hi Lavi,

the problem is the DHIS version - we implemented support for CRUD operations at the various end-points in version 2.15. Could you please update to 2.15 and try again?

dhis2.org/downloads

regards,

Lars

PS. we need to version our docs but haven’t gotten around to do it yet.

On Sun, Jun 29, 2014 at 1:08 PM, Lavi Shpigelman shpigi@gmail.com wrote:

Hi
I have a server (on Linux, running on Tomcat) with and empty dhis app running (version 2.14)

I would like to populate it with data (and metadata) using the web API.

I tried an example from the documentation:

I created a file called pi.xml:

<constant name="PI" xmlns="[http://dhis2.org/schema/dxf/2.0](http://dhis2.org/schema/dxf/2.0)  "> <value>3.14159265359</value> </constant>
and gave this command from my windows command line:

C:\>curl.exe -d @pi.xml "http://<my host name>:8080/dhis/api/constants" -H "Content-Type:application/xml" -u admin:district -v




The server responded with
<html><head><title>Apache Tomcat/7.0.52 (Debian) - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 405 - Request method 'POST' not supported</h1><HR size="1" noshade="noshade"><p><b>type</b>Status report</p><p><b>message</b> <u>Request method 'POST' not supported</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52 (Debian)</h3></body></html>




when I tried the same with https (instead of http), I got the reply:
C:\>curl.exe -d @pi.xml "https://<my host name>:8080/dhis/api/constants" - H "Content-Type:application/xml" -u admin:district -v * Hostname was NOT found in DNS cache * Trying <my host ip address>... * Connected to <my host name> (<my host ip adress>) port 8080 (#0) * schannel: SSL/TLS connection with <my host name> port 8080 (step 1/3)
* schannel: checking server certificate revocation * schannel: sending initial handshake data: sending 171 bytes... * schannel: sent initial handshake data: sent 171 bytes * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: failed to receive handshake, need more data * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: encrypted data buffer: offset 144 length 4096 * schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid * Closing connection 0 * schannel: shutting down SSL/TLS connection with <my host name> port 8080 * schannel: clear security context handle * schannel: clear credential handle curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

The same command (using https with my windows curl) was successful when sent to the dhis web site demo app

I am guessing that creating objects in dhis requires a secure connection and that my server does not currently support it. (or does not support the specific ssh protocol that curl uses?) 
Is this the problem or am I missing something?


Thanks,
Lavi

Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Hi Lavi

Could you see if changing the payload to:


  <value>3.14159265359</value>
</constant>

Works for you? you must use the endpoint /api/metaData instead

···


Morten

On Thu, Jul 3, 2014 at 3:33 PM, Lavi Shpigelman shpigi@gmail.com wrote:

Thanks for the clarification, Lars !

The problem is that I would prefer to stay compatible with the version currently used by our collaborators which is actually 2.13.

I’m, guessing there must be a way to push data to this version.

Can you specify what it is (perhaps access to 2.13 documentation would help)?

Best regards,

Lavi


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

On Tue, Jul 1, 2014 at 3:25 PM, Lars Helge Øverland larshelge@gmail.com wrote:

Hi Lavi,

the problem is the DHIS version - we implemented support for CRUD operations at the various end-points in version 2.15. Could you please update to 2.15 and try again?

dhis2.org/downloads

regards,

Lars

PS. we need to version our docs but haven’t gotten around to do it yet.

On Sun, Jun 29, 2014 at 1:08 PM, Lavi Shpigelman shpigi@gmail.com wrote:

Hi
I have a server (on Linux, running on Tomcat) with and empty dhis app running (version 2.14)

I would like to populate it with data (and metadata) using the web API.

I tried an example from the documentation:

I created a file called pi.xml:

<constant name="PI" xmlns="[http://dhis2.org/schema/dxf/2.0](http://dhis2.org/schema/dxf/2.0)  "> <value>3.14159265359</value> </constant>
and gave this command from my windows command line:

C:\>curl.exe -d @pi.xml "http://<my host name>:8080/dhis/api/constants" -H "Content-Type:application/xml" -u admin:district -v






The server responded with
<html><head><title>Apache Tomcat/7.0.52 (Debian) - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 405 - Request method 'POST' not supported</h1><HR size="1" noshade="noshade"><p><b>type</b>Status report</p><p><b>message</b> <u>Request method 'POST' not supported</u></p><p><b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52 (Debian)</h3></body></html>






when I tried the same with https (instead of http), I got the reply:
C:\>curl.exe -d @pi.xml "https://<my host name>:8080/dhis/api/constants" - H "Content-Type:application/xml" -u admin:district -v * Hostname was NOT found in DNS cache * Trying <my host ip address>... * Connected to <my host name> (<my host ip adress>) port 8080 (#0) * schannel: SSL/TLS connection with <my host name> port 8080 (step 1/3)
* schannel: checking server certificate revocation * schannel: sending initial handshake data: sending 171 bytes... * schannel: sent initial handshake data: sent 171 bytes * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: failed to receive handshake, need more data * schannel: SSL/TLS connection with <my host name> port 8080 (step 2/3)
* schannel: encrypted data buffer: offset 144 length 4096 * schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid * Closing connection 0 * schannel: shutting down SSL/TLS connection with <my host name> port 8080 * schannel: clear security context handle * schannel: clear credential handle curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - The token supplied to the function is invalid

The same command (using https with my windows curl) was successful when sent to the dhis web site demo app

I am guessing that creating objects in dhis requires a secure connection and that my server does not currently support it. (or does not support the specific ssh protocol that curl uses?) 
Is this the problem or am I missing something?


Thanks,
Lavi

Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

To add to this, yes you can use the generic meta data resource to import a
meta-data payload which can contain all types of objects.

Docs here: https://www.dhis2.org/doc/snapshot/en/user/html/ch31s05.html

regards,

Lars