DataFlex / Creatio API / $batch parameter (Content-Type: multipart/mixed and different changesets)
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get ComAppend Of hoSbRequestBody "--batch_a685-9724-d873" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "--changeset_06da-d998-8e7e" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: application/http" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Transfer-Encoding: binary" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "POST {{CollectionName5}} HTTP/1.1" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-ID: 1" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: application/json;odata=verbose" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody '{"{{FieldName6}}": "{{FieldName6Value3}}", "{{FieldName1}}": "{{FieldName1Value11}}"}' + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "--batch_a685-9724-d873" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "--changeset_06da-d998-8e71" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: application/http" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Transfer-Encoding: binary" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "POST {{CollectionName5}} HTTP/1.1" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-ID: 2" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody "Content-Type: application/json;odata=verbose" + (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody (character(10)) To iSuccess
Get ComAppend Of hoSbRequestBody '{"{{FieldName6}}": "{{FieldName6Value4}}", "{{FieldName1}}": "{{FieldName1Value12}}"}' To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true"
Send ComSetRequestHeader To hoHttp "BPMCSRF" "{{BPMCSRF}}"
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Send ComSetRequestHeader To hoHttp "ForceUseSession" "true"
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComPTextSb Of hoHttp "POST" "https://myserver.com/0/odata/$batch" vSbRequestBody "utf-8" "multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true" False False To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
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}"
}
]
}