PowerBuilder / Creatio API / $batch parameter (Content-Type: multipart/mixed and different changesets)
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbRequestBody
oleobject loo_Resp
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_SbRequestBody.Append("--batch_a685-9724-d873~n")
loo_SbRequestBody.Append("Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("--changeset_06da-d998-8e7e~n")
loo_SbRequestBody.Append("Content-Type: application/http~n")
loo_SbRequestBody.Append("Content-Transfer-Encoding: binary~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("POST {{CollectionName5}} HTTP/1.1~n")
loo_SbRequestBody.Append("Content-ID: 1~n")
loo_SbRequestBody.Append("Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1~n")
loo_SbRequestBody.Append("Content-Type: application/json;odata=verbose~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("{~"{{FieldName6}}~": ~"{{FieldName6Value3}}~", ~"{{FieldName1}}~": ~"{{FieldName1Value11}}~"}~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("--batch_a685-9724-d873~n")
loo_SbRequestBody.Append("Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("--changeset_06da-d998-8e71~n")
loo_SbRequestBody.Append("Content-Type: application/http~n")
loo_SbRequestBody.Append("Content-Transfer-Encoding: binary~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("POST {{CollectionName5}} HTTP/1.1~n")
loo_SbRequestBody.Append("Content-ID: 2~n")
loo_SbRequestBody.Append("Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1~n")
loo_SbRequestBody.Append("Content-Type: application/json;odata=verbose~n")
loo_SbRequestBody.Append("~n")
loo_SbRequestBody.Append("{~"{{FieldName6}}~": ~"{{FieldName6Value4}}~", ~"{{FieldName1}}~": ~"{{FieldName1Value12}}~"}")
loo_Http.SetRequestHeader("Content-Type","multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true")
loo_Http.SetRequestHeader("BPMCSRF","{{BPMCSRF}}")
loo_Http.SetRequestHeader("Accept","application/json")
loo_Http.SetRequestHeader("ForceUseSession","true")
loo_Resp = loo_Http.PTextSb("POST","https://myserver.com/0/odata/$batch",loo_SbRequestBody,"utf-8","multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_SbRequestBody
return
end if
Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp
destroy loo_Http
destroy loo_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}"
}
]
}