delphiAx / Creatio API / $batch parameter (Content-Type: multipart/mixed and different changesets)
Back to Collection Items
var
http: TChilkatHttp;
success: Integer;
sbRequestBody: TChilkatStringBuilder;
resp: IChilkatHttpResponse;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
sbRequestBody := TChilkatStringBuilder.Create(Self);
sbRequestBody.Append('--batch_a685-9724-d873' + #10);
sbRequestBody.Append('Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('--changeset_06da-d998-8e7e' + #10);
sbRequestBody.Append('Content-Type: application/http' + #10);
sbRequestBody.Append('Content-Transfer-Encoding: binary' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('POST {{CollectionName5}} HTTP/1.1' + #10);
sbRequestBody.Append('Content-ID: 1' + #10);
sbRequestBody.Append('Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + #10);
sbRequestBody.Append('Content-Type: application/json;odata=verbose' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('{"{{FieldName6}}": "{{FieldName6Value3}}", "{{FieldName1}}": "{{FieldName1Value11}}"}' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('--batch_a685-9724-d873' + #10);
sbRequestBody.Append('Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('--changeset_06da-d998-8e71' + #10);
sbRequestBody.Append('Content-Type: application/http' + #10);
sbRequestBody.Append('Content-Transfer-Encoding: binary' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('POST {{CollectionName5}} HTTP/1.1' + #10);
sbRequestBody.Append('Content-ID: 2' + #10);
sbRequestBody.Append('Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + #10);
sbRequestBody.Append('Content-Type: application/json;odata=verbose' + #10);
sbRequestBody.Append(#10);
sbRequestBody.Append('{"{{FieldName6}}": "{{FieldName6Value4}}", "{{FieldName1}}": "{{FieldName1Value12}}"}');
http.SetRequestHeader('Content-Type','multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true');
http.SetRequestHeader('BPMCSRF','{{BPMCSRF}}');
http.SetRequestHeader('Accept','application/json');
http.SetRequestHeader('ForceUseSession','true');
resp := http.PTextSb('POST','https://myserver.com/0/odata/$batch',sbRequestBody.ControlInterface,'utf-8','multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true',0,0);
if (http.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
Memo1.Lines.Add(IntToStr(resp.StatusCode));
Memo1.Lines.Add(resp.BodyStr);
Curl Command
curl -X POST
-H "Content-Type: multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true"
-H "BPMCSRF: {{BPMCSRF}}"
-H "Accept: application/json"
-H "ForceUseSession: true"
-d '--batch_a685-9724-d873
Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e
--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary
POST {{CollectionName5}} HTTP/1.1
Content-ID: 1
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose
{"{{FieldName6}}": "{{FieldName6Value3}}", "{{FieldName1}}": "{{FieldName1Value11}}"}
--batch_a685-9724-d873
Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71
--changeset_06da-d998-8e71
Content-Type: application/http
Content-Transfer-Encoding: binary
POST {{CollectionName5}} HTTP/1.1
Content-ID: 2
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose
{"{{FieldName6}}": "{{FieldName6Value4}}", "{{FieldName1}}": "{{FieldName1Value12}}"}'
https://myserver.com/0/odata/$batch
Postman Collection Item JSON
{
"name": "$batch parameter (Content-Type: multipart/mixed and different changesets)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true"
},
{
"key": "BPMCSRF",
"type": "text",
"value": "{{BPMCSRF}}"
},
{
"key": "Accept",
"type": "text",
"value": "application/json"
},
{
"key": "ForceUseSession",
"type": "text",
"value": "true"
}
],
"body": {
"mode": "raw",
"raw": "--batch_a685-9724-d873\nContent-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPOST {{CollectionName5}} HTTP/1.1\nContent-ID: 1\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose\n\n{\"{{FieldName6}}\": \"{{FieldName6Value3}}\", \"{{FieldName1}}\": \"{{FieldName1Value11}}\"}\n\n--batch_a685-9724-d873\nContent-Type: multipart/mixed; boundary=changeset_06da-d998-8e71\n\n--changeset_06da-d998-8e71\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPOST {{CollectionName5}} HTTP/1.1\nContent-ID: 2\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose\n\n{\"{{FieldName6}}\": \"{{FieldName6Value4}}\", \"{{FieldName1}}\": \"{{FieldName1Value12}}\"}",
"options": {
"raw": {
"language": "text"
}
}
},
"url": {
"raw": "{{BaseURI}}/0/odata/$batch",
"host": [
"{{BaseURI}}"
],
"path": [
"0",
"odata",
"$batch"
]
},
"description": "Batch request with different types of returned content and different user changesets (uses the [$batch](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingtheBatchEndpointforaServic) parameter)."
},
"response": [
{
"name": "[200] Batch request with Content-Type: multipart/mixed and different changesets",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true"
},
{
"key": "BPMCSRF",
"type": "text",
"value": "{{BPMCSRF}}"
},
{
"key": "Accept",
"type": "text",
"value": "application/json"
},
{
"key": "ForceUseSession",
"type": "text",
"value": "true"
}
],
"body": {
"mode": "raw",
"raw": "--batch_a685-9724-d873\nContent-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPOST City HTTP/1.1\nContent-ID: 1\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose\n\n{\"Id\": \"d6bc67b1-9943-4e47-9aaf-91bf83e9c285\", \"Name\": \"Nebraska\"}\n\n--batch_a685-9724-d873\nContent-Type: multipart/mixed; boundary=changeset_06da-d998-8e71\n\n--changeset_06da-d998-8e71\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPOST City HTTP/1.1\nContent-ID: 2\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose\n\n{\"Id\": \"d6bc67b1-9943-4e47-9aaf-91bf83e9c286\", \"Name\": \"Durham\"}",
"options": {
"raw": {
"language": "text"
}
}
},
"url": {
"raw": "https://myserver.com/0/odata/$batch",
"protocol": "https",
"host": [
"myserver",
"com"
],
"path": [
"0",
"odata",
"$batch"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "Text",
"header": [
],
"cookie": [
],
"body": "{\r\n \"responses\": [\r\n {\r\n \"id\": \"1\",\r\n \"atomicityGroup\": \"e9621f72-42bd-47c1-b271-1027e4b68e3b\",\r\n \"status\": 201,\r\n \"headers\": {\r\n \"location\": \"https://myserver.com/0/odata/City(d6bc67b1-9943-4e47-9aaf-91bf83e9c285)\",\r\n \"content-type\": \"application/json; odata.metadata=minimal\",\r\n \"odata-version\": \"4.0\"\r\n },\r\n \"body\": {\r\n \"@odata.context\": \"https://myserver.com/0/odata/$metadata#City/$entity\",\r\n \"Id\": \"d6bc67b1-9943-4e47-9aaf-91bf83e9c285\",\r\n \"CreatedOn\": \"2020-05-18T18:49:16.3766324Z\",\r\n \"CreatedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\r\n \"ModifiedOn\": \"2020-05-18T18:49:16.3766324Z\",\r\n \"ModifiedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\r\n \"Name\": \"Nebraska\",\r\n \"Description\": \"\",\r\n \"CountryId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"RegionId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"TimeZoneId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"ProcessListeners\": 0\r\n }\r\n },\r\n {\r\n \"id\": \"2\",\r\n \"atomicityGroup\": \"960e2272-d8cb-4b4d-827c-0181485dd71d\",\r\n \"status\": 201,\r\n \"headers\": {\r\n \"location\": \"https://myserver.com/0/odata/City(d6bc67b1-9943-4e47-9aaf-91bf83e9c286)\",\r\n \"content-type\": \"application/json; odata.metadata=minimal\",\r\n \"odata-version\": \"4.0\"\r\n },\r\n \"body\": {\r\n \"@odata.context\": \"https://myserver.com/0/odata/$metadata#City/$entity\",\r\n \"Id\": \"d6bc67b1-9943-4e47-9aaf-91bf83e9c286\",\r\n \"CreatedOn\": \"2020-05-18T18:49:16.4078852Z\",\r\n \"CreatedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\r\n \"ModifiedOn\": \"2020-05-18T18:49:16.4078852Z\",\r\n \"ModifiedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\r\n \"Name\": \"Durham\",\r\n \"Description\": \"\",\r\n \"CountryId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"RegionId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"TimeZoneId\": \"00000000-0000-0000-0000-000000000000\",\r\n \"ProcessListeners\": 0\r\n }\r\n }\r\n ]\r\n}"
}
]
}