Is a batch operation to save a set of navigation properties possible? - json

For example: Company has Employees.
By posting to odata.svc/Company(1)/Employees/$ref, I can save Company-Employee relation. Can I save multiple Company-Employee links this way using odata.svc/Company(1)/Employees/$ref/$batch ?
I tried but didnt work. If this is incorrect way, is there any other alternative ?

OData does support batching, I'm not sure what version of OData you are using but here is some documentation from v3 (v4 is the same) http://www.odata.org/documentation/odata-version-3-0/batch-processing/
In your example batch URL, you are adding $batch to the end of the URL that you are using, instead you have to POST to odata.svc/$batch with a request that contains details of all of the operations that you want to perform. For example, here is one of the request taken from that link:
POST /service/$batch HTTP/1.1 Host: host Content-Type:
multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b
--batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: multipart/mixed;
boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621
Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1
POST /service/Customers HTTP/1.1 Host: host Content-Type:
application/atom+xml;type=entry Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Type: application/http Content-Transfer-Encoding: binary
POST $1/Orders HTTP/1.1 Host: host Content-Type:
application/atom+xml;type=entry Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621--
--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

Related

send POST request html

I'm trying to create a post request from the following header.
POST /Create_New_Account.php HTTP/1.0
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------092818025341241
Content-Length: 198
Host: test.com
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
----------092818025341241
Content-Disposition: form-data; name="email"
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
test#yahoo.com
----------092818025341241--
I tried using http://test.com/Create_New_Account.php?email=test#yahoo.com
but it didn't work i.e. no account was created. should i be adding anything else to my request?
I tried using http://test.com/Create_New_Account.php?email=test#yahoo.com but it didn't work
Possibly, Create_New_Account.php uses $_POST in order to get parameter email, with given link email is accesible through $_GET or $_REQUEST and not $_POST, which is why the overall create account operation fails.

Content-type application/json causes 415 Unsupported Media Type

I am testing Forge API, and I have been able to complete requests smoothly for most endpoints, except the GET Hubs - I kept getting a 415 Unsupported Media Type.
Strangely enough, after I remove the Content-Type header - which was the same header used for all the other end-points of Content-Type:application/json -
the request worked and returns a 200 with the correct data.
Is there something about content-type I am not familiar with?
Shouldn't the first request work?
Request 1 - Returns 415 for hubs endpoint: no data
GET https://developer.api.autodesk.com/project/v1/hubs HTTP/1.1
Host: developer.api.autodesk.com
Authorization: Bearer {{ACCESS_TOKEN}}
Content-Type: application/json
Cache-Control: no-cache
Request 2 - Returns 200: data ok
GET https://developer.api.autodesk.com/project/v1/hubs HTTP/1.1
Host: developer.api.autodesk.com
Authorization: Bearer {{ACCESS_TOKEN}}
Cache-Control: no-cache
The JSON API defines that the client MUST send Content-Type: application/vnd.api+json
Answering my own question based on the comments (thanks #chetan-ranpariya)
You don't need to pass a Content-type on GET requests
the API should ignore the header; issue has been reported to API team

How can I put Google Drive API files.list requests for different users in the same batch request?

Normally, one would use BatchHttpRequest to aggregate several requests, but what if I want to list files for two different users?
Nominally that requires an oauth2 token per-user. BatchHttpRequest either takes one http object (which handles the credentials) for the batch, or pulls it out of the first batched request encountered when .execute() is called.
Using oauth1 to sign each batched requests results in proper results (different feeds for each user). However, using oauth2 and manually constructing the payload results in identical feeds (matching the user in the first batched request):
POST /batch HTTP/1.1
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=blah
Content-Length: 572
accept-encoding: gzip, deflate
Cache-Control: no-cache
--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+1>
GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQAabvlG2hnRPyEAAADUm7vkDe_qg7L49R655IyxvgBnkN7_PEgE3IG7UnZ_ZEmJwUK_6fSV4kTHjNQIjTk
accept: application/json
--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+2>
GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQBu8f9W8S5E6RwAAAAPqCOiqoFW3QEFYkBvQGx36UVKNHeEhdZT8GPN-P74ng
accept: application/json
--blah
Since oauth1 works, it seems that this is at least theoretically possible, although I may be blocked by a google bug where the oauth2 token for the first request in the batch overrides any other authorizations included.
The google-provided client does not support this, but providing an Authorization header for each request will work. The example given should work assuming all of the authorization header values are correct.

Box API - The Timestamp type

I'm trying to upload a file via Box API and I want to specify the content_modified_at parameter. However, I always receive an error in response, saying that I specify the date not in ISO 8601 format. I double-checked the format I'm sending, and it's definitely ISO 8601.
If I don't specify this field, the file is created successfully.
The field in my request has format "2013-04-21T19:39:16+03:00",
and I'm not sure how this is different from "2012-12-12T11:04:26-08:00" that is used in Box API docs
Here is the full listing of my request and response:
-------------- REQUEST --------------
POST https://upload.box.com/api/2.0/files/content
Accept-Encoding: gzip
Authorization: Bearer [hidden]
User-Agent: Google-HTTP-Java-Client/1.14.1-beta (gzip)
Content-Type: multipart/form-data; boundary=__END_OF_PART__
--__END_OF_PART__
Content-Type: application/octet-stream
content-disposition: form-data; name="filename"; filename="file1.txt"
1234567890
--__END_OF_PART__
content-disposition: form-data; name="parent_id"
760503410
--__END_OF_PART__
content-disposition: form-data; name="content_modified_at"
2013-04-21T19:39:16+03:00
--__END_OF_PART__--
-------------- RESPONSE --------------
HTTP/1.1 400 Bad Request
Date: Sun, 21 Apr 2013 17:01:23 GMT
Content-Length: 193
X-Error-Handling: entry;index.php|rid;132352423451741b638d902|runmode;box_api_v2|user;2|user;193761140|
Connection: close
Content-Type: application/json
Server: Apache/2.2.15 (Scientific Linux)
Cache-Control: no-cache, no-store
{"type":"error","status":400,"code":"bad_request","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"not a valid iso 8601 formatted date","request_id":"132352423451741b638d902"}
UPDATE:
Does anybody of the Box team actually care about this? Does it mean there is a mistake in the services or just nobody wants to explain me what was my fault?
There is an issue with our time stamp parser that we're in the process of fixing.
You should see now issues if you set the timestamp to UTC and send it with a
timezone offset of -00:00, e.g.
2013-04-17T09:12:36-00:00
Again, this is an issue on our end that we're working on resolving.

multipart/mixed HTTP request in actionscript

Is there an easy way to make an multipart/mixed HTTP request in as3?
I'm trying to reach LightSwitch server using OData protocol from flash. To send multiple commands at once you can combine them in one batch using HTTP request with "multipart/mixed" content type.
Here an example of HTTP requests with two commands:
Content-Type:multipart/mixed; boundary=batch
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT http://localhost:18065/ApplicationData.svc/Orders(3)/$links/User HTTP/1.1
Content-Type: application/json;odata=verbose
{"uri": "http://localhost:18065/ApplicationData.svc/Users(4)"}
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE http://localhost:18065/ApplicationData.svc/Users(3) HTTP/1.1
Content-Type: application/json;odata=verbose
If-Match: W/"X'0000000000002715'"
{"Name": "User 3_"}
--changeset--
--batch--
Every part contains own HTTP headers and body. Response formatted the same way, with own http response code.
How to work with multiple HTTP requests in actionscript?