question

davidbolivar avatar image
davidbolivar asked

Get an Empty {} Restful API response when creating a node

Trying to create a folder node. The information on this web page does not seem to be accurate or consistent: https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes Firstly it only matters that a parameter is set. It does not matter what the parameter name is. If no parameters are supplied then Cloud Drive complains that the [b]kind[/b] parameter is not set. But really Cloud Drive does not care if the [b]kind[/b] parameter is there or not as long as one parameter of any name (even one not on the list) is present. Likewise with the [b]access_token[/b]. Cloud Drive only cares that one is specified and does not care what the value is. In all cases when the [b]access_token[/b] is present (right or wrong) and at least one arbitrarily named parameter is included (any value) the create node restful API call always returns "{}" with an http status of 400. Even when the parameters are specified exactly as shown in the example - again "{}" and http status 400 is always returned. This function would appear to be broken. All the other Amazon Cloud Drive Restful API calls return error information except for this one. Please clarify the proper method to retrieve error information from this call. The page talks about a [b]localId[/b] which is supposed to be coded in the URL as a get parameter would be. However in the example this is not done. So which is it? Is localID coded into the uRL as a get parameter when using a POST operation? Or it is entirely not used as shown in the example? If the locaIId is needed then the next question is exactly what is it? Is localId the [b]client_id[/b] for the web app or perhaps is it the Amazon [b]user_id[/b] for the Cloud Drive owner? Please clarify. I have tried both and neither work. I have also tried using the id of the root node. What is the exact process to obtain a [b]localId[/b]? If the contentURL rather than the metatdataURL is used Cloud Drive complains the resource does not exists. If a GET is used rather than a POST Cloud Drive returns all the meta data for the entire cloud drive. Is there some sample code that creates a node or more up to date documentation on this topic? Is there a better way to create a folder node? Please advise.
amazon drive
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

davidbolivar avatar image
davidbolivar answered
After some more work it turns out there are two problems that make performing a POST using php curl a no-go. The first is that unlike the GET operations that work so well with php curl, the Amazon Cloud does not issue error messages other than "400, {}" and "500, 'Internal system error'" when php curl is used to do a POST. This makes diagnosing what is wrong pretty much impossible. The second problem is that php curl, while it has the same name as the command line curl, operates very differently than it's command line counterpart. So the solution would seem to be to use php curl for GET operations and php shell_exec the curl command when doing to POST. Further testing reveals that the suppress= option can be omitted as Amazon Cloud rejects duplicate files (based on the MD5 hash) no matter what this option is set to. Still not sure what the localId value is for, but again testing shows it can be omitted. Message was edited by: davidbolivar Message was edited by: davidbolivar
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

davidbolivar avatar image
davidbolivar answered
A bit more information. While the shell_exec of the curl command works for uploading files there does not seem to be a way to create a node. Using the "Create Folder" example given here: https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes Results in the following output: curl -v -X POST --data '{"name":"CAM yehdsju7d","kind":"FOLDER","parents":["dzzfmfz8SWm24Z9HvsqYTw"}]' https://content-na.drive.amazonaws.com/cdproxy/nodes --header "Authorization: Bearer Atza|IQEBLjAsAhQiH7RgJ9FTmlGb_gF6272Eyo-OlgIUKTBwTa5EEFJQRqY5DUoO_yvCSZ74KlSg93wIkrL5O6OfIW6F4IlM_C_vbhjg3XXU-BEgQw6aSkfL_BeiCPQxczCxnKeNmMAiXRx6r1rEn2sJ1AAYircOww1nrFQBR5-Y91feuTRj68iTyK_JTJ3nKb1NOqZwmSuSLumFzmogq_GeJwWIrvEDiAOwR3PtssD1vP9GVxfWadZj8RFD6czQU0uIxb0BmATpIMhQ1M-_jFZuVlUCevmmFlP2BwK2bYr9GM4cqQI_uOZW5z6ptz5-V_e47b7sMVdoLYpgznPYKYFg8uMEHxz793QEBYq33IO8-jBSYg28rhn2RVVycVaHq7rGcsyz4PqzSatv7IpHgFmy_KjA04SCfkNDUuhZ9Q-tAiloro91lbtVXuSL94phmTnMW0eaFfs-7YiZOHy5TJUfVYcoTLrM4ZRVKfD8VZrEcc_AGqGKs6mbE8pN5oOyAqWE8h_e" Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 54.165.15.106... * Connected to content-na.drive.amazonaws.com (54.165.15.106) port 443 (#0) * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * TLSv1.2 (OUT), TLS header, Certificate Status (22): * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Client hello (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server did not agree to a protocol * Server certificate: * subject: C=US; ST=Washington; L=Seattle; O= Amazon.com, Inc.; CN= content-na.drive.amazonaws.com * start date: Sep 18 00:00:00 2015 GMT * expire date: Oct 20 23:59:59 2016 GMT * subjectAltName: content-na.drive.amazonaws.com matched * issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4 * SSL certificate verify ok. > POST /cdproxy/nodes HTTP/1.1 > Host: content-na.drive.amazonaws.com > User-Agent: curl/7.45.0 > Accept: */* > Authorization: Bearer Atza|IQEBLjAsAhQiH7RgJ9FTmlGb_gF6272Eyo-OlgIUKTBwTa5EEFJQRqY5DUoO_yvCSZ74KlSg93wIkrL5O6OfIW6F4IlM_C_vbhjg3XXU-BEgQw6aSkfL_BeiCPQxczCxnKeNmMAiXRx6r1rEn2sJ1AAYircOww1nrFQBR5-Y91feuTRj68iTyK_JTJ3nKb1NOqZwmSuSLumFzmogq_GeJwWIrvEDiAOwR3PtssD1vP9GVxfWadZj8RFD6czQU0uIxb0BmATpIMhQ1M-_jFZuVlUCevmmFlP2BwK2bYr9GM4cqQI_uOZW5z6ptz5-V_e47b7sMVdoLYpgznPYKYFg8uMEHxz793QEBYq33IO8-jBSYg28rhn2RVVycVaHq7rGcsyz4PqzSatv7IpHgFmy_KjA04SCfkNDUuhZ9Q-tAiloro91lbtVXuSL94phmTnMW0eaFfs-7YiZOHy5TJUfVYcoTLrM4ZRVKfD8VZrEcc_AGqGKs6mbE8pN5oOyAqWE8h_e > Content-Length: 77 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 77 out of 77 bytes < HTTP/1.1 400 Bad Request < Content-Type: application/vnd.error+json < Date: Sat, 12 Mar 2016 17:08:48 GMT < Server: Amazon-Cloud-Drive < x-amzn-RequestId: 2a6912d2-e8c9-4224-accc-d36993dfb37b < Content-Length: 163 < Connection: keep-alive < * Connection #0 to host content-na.drive.amazonaws.com left intact {"message":"Invalid Content-Type. Expected \u0027multipart/form-data\u0027 or \u0027multipart/mixed\u0027, received \u0027application/x-www-form-urlencoded\u0027"} If a header is added that specifies mutlipart-form the response is "500, 'Internal System Error'". Is there a curl example of creating a node that works? Thank you in advance.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rambalac avatar image
rambalac answered
Your JSON is wrong {"name":"CAM yehdsju7d","kind":"FOLDER","parents":["dzzfmfz8SWm24Z9HvsqYTw"}]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

davidbolivar avatar image
davidbolivar answered
Could you please share an example of what would be the correct json?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rambalac avatar image
rambalac answered
I mean it's not JSON.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.