delphiDll / Creatio API / $batch parameter (Content-Type: multipart/mixed and different changesets)
Back to Collection Items
var
http: HCkHttp;
success: Boolean;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
sbRequestBody := CkStringBuilder_Create();
CkStringBuilder_Append(sbRequestBody,'--batch_a685-9724-d873' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'--changeset_06da-d998-8e7e' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: application/http' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Transfer-Encoding: binary' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'POST {{CollectionName5}} HTTP/1.1' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-ID: 1' + #10);
CkStringBuilder_Append(sbRequestBody,'Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: application/json;odata=verbose' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'{"{{FieldName6}}": "{{FieldName6Value3}}", "{{FieldName1}}": "{{FieldName1Value11}}"}' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'--batch_a685-9724-d873' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'--changeset_06da-d998-8e71' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: application/http' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Transfer-Encoding: binary' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'POST {{CollectionName5}} HTTP/1.1' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-ID: 2' + #10);
CkStringBuilder_Append(sbRequestBody,'Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + #10);
CkStringBuilder_Append(sbRequestBody,'Content-Type: application/json;odata=verbose' + #10);
CkStringBuilder_Append(sbRequestBody,#10);
CkStringBuilder_Append(sbRequestBody,'{"{{FieldName6}}": "{{FieldName6Value4}}", "{{FieldName1}}": "{{FieldName1Value12}}"}');
CkHttp_SetRequestHeader(http,'Content-Type','multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true');
CkHttp_SetRequestHeader(http,'BPMCSRF','{{BPMCSRF}}');
CkHttp_SetRequestHeader(http,'Accept','application/json');
CkHttp_SetRequestHeader(http,'ForceUseSession','true');
resp := CkHttp_PTextSb(http,'POST','https://myserver.com/0/odata/$batch',sbRequestBody,'utf-8','multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbRequestBody);
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}"
}
]
}