The API supports OData batch requests as described on odata.org. This is useful in cases where there is a need for data that is linked, such as a SurveyResult.
A batch request is done via a multipart/mixed query. Every part is a HTTP document, which is then again a normal HTTP request. This is done that way because a multipart has headers, but not HTTP verb and URL, like (POST /api/v20...).
If you want to refer to a result from an earlier request, provide a `Content-ID` header in the http request that you need to refer to. The URL and Id to that object is then stored in a variable, that can be used later. For instance, in a POST /api/v24/SurveyResult can have the Content-ID: 1, and later, when adding a SurveyAnswer, you can provide "ResultId": "$1".
POST /odata/v24/$batch HTTP/1.1 Host: company.landax.no Content-Type: multipart/mixed;boundary=batch_cb2ce436-ea4e-4e8a-8a63-171ea74a0146 OData-Version: 4.0 Authorization: Bearer TOKEN Content-Length: ### --batch_cb2ce436-ea4e-4e8a-8a63-171ea74a0146 Content-Type: multipart/mixed;boundary=changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc --changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1 POST /odata/v24/SurveyResult HTTP/1.1 Host: company.landax.no Content-Type: application/json Content-Length: ### {"DefinitionId": 287, "Name": "Test Survey Result"} --changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 2 POST /odata/v24/SurveyAnswer HTTP/1.1 Host: company.landax.no Content-Type: application/json Content-Length: ### {"ResultId":"$1","QuestionId": 3669, "Text": "Answer Text"} --changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 3 POST /odata/v24/SurveyAnswer HTTP/1.1 Host: company.landax.no Content-Type: application/json Content-Length: ### {"ResultId":"$1","QuestionId": 3670, "Value": 123} --changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 4 POST /odata/v24/Document/CreateDocument HTTP/1.1 Host: company.landax.no Content-Type: multipart/form-data;boundary=data_cb2ce436-ea4e-4e8a-8b61-171ea74a12145 Content-Length: ### --data_cb2ce436-ea4e-4e8a-8b61-171ea74a12145 Content-Disposition: form-data; name="document" { "FileName": "image.jpg", "ModuleId": 120 } --data_cb2ce436-ea4e-4e8a-8b61-171ea74a12145 Content-Disposition: form-data; name="documentLink" { "SurveyAnswerId": "$2" } --data_cb2ce436-ea4e-4e8a-8b61-171ea74a12145 Content-Disposition: form-data; name="fileData"; filename="image.jpg" Content-Type: image/jpeg ##BINARY FILE DATA## --data_cb2ce436-ea4e-4e8a-8b61-171ea74a12145-- --changeset_cdaf34bc-2f49-4613-b32e-3e3773c371bc-- --batch_cb2ce436-ea4e-4e8a-8a63-171ea74a0146-- Will result in this response: HTTP/1.1 200 OK Content-Type: multipart/mixed;boundary=b_33d00764-8fe7-5bba-83fe-bf2fb35fe046 OData-Version: 4.0 DataServiceVersion: 4.0 --headers-- Content-Length: ### --b_33d00764-8fe7-5bba-83fe-bf2fb35fe046 Content-Type: multipart/mixed;boundary=cs_d0463014-5092-56b1-975f-fe66b9e1d409 --cs_d0463014-5092-56b1-975f-fe66b9e1d409 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1 HTTP/1.1 201 Created Content-Type: application/json;charset=utf-8 Location: https://company.landax.no/odata/v24/SurveyResults(2913) --headers-- Content-Length: ### {"SurveyId":171,"DefinitionId":287,"Number":"4", ...result data..., "@odata.context":"/api/v20/$metadata#SurveyResults/$entity","@odata.type":"#Landax.Data.SurveyResult"} --cs_d0463014-5092-56b1-975f-fe66b9e1d409 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 2 HTTP/1.1 201 Created Content-Type: application/json;charset=utf-8 --headers-- Location: https://company.landax.no/odata/v24/SurveyAnswers(39089) Content-Length: ### {"ResultId":2913,"QuestionId":3669,...answer data...,"@odata.context":"/api/v20/$metadata#SurveyAnswers/$entity","@odata.type":"#Landax.Data.SurveyAnswer"} --cs_d0463014-5092-56b1-975f-fe66b9e1d409 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 3 HTTP/1.1 201 Created Content-Type: application/json;charset=utf-8 ...headers... Location: https://company.landax.no/odata/v24/SurveyAnswers(39090) Content-Length: ### {"ResultId":2913,"QuestionId":3670,...answer data...,"@odata.context":"/api/v20/$metadata#SurveyAnswers/$entity","@odata.type":"#Landax.Data.SurveyAnswer"} --cs_d0463014-5092-56b1-975f-fe66b9e1d409 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 4 HTTP/1.1 200 OK Content-Type: application/json;charset=utf-8 ...headers... Content-Length: ### {"@odata.context":"/odata/v24/$metadata#Document/CreateDocument","value":{"document":{"Id":10985,"DocumentId":10985,"VersionId":10916,"Status":"published","FileName":"image.jpg", ...document data...},"documentLink":{"Id":9445,"Guid":"757c11f9-46a5-5e75-9da2-fdae48967c7c","DocumentId":10985,"VersionId":10916,"SurveyAnswerId":39089,...link data...}}} --cs_d0463014-5092-56b1-975f-fe66b9e1d409-- --b_33d00764-8fe7-5bba-83fe-bf2fb35fe046--
The response parts will keep the same "Content-ID" as the request parts, so it is easy to map them. HTTP parsing must be done by client. This is a typical http multipart response, and there should be parsers out there for those.
Manual parsing can be done by splitting on first double empty line. Above those are headers, below those until --boundary will be content. Content can be parsed through same function until we have a plain body.