Swift / Creatio API / $batch parameter (Content-Type: application/json and Prefer: continue-on-error)
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()
var success: Bool
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "requests": [
// {
// "method": "POST",
// "url": "{{CollectionName5}}",
// "id": "t3",
// "body": {
// "{{FieldName1}}": "{{FieldName1Value4}}"
// },
// "headers": {
// "Content-Type": "application/json;odata=verbose",
// "Accept": "application/json;odata=verbose",
// "Prefer": "continue-on-error"
// }
// },
// {
// "method": "PATCH",
// "atomicityGroup": "g1",
// "url": "{{CollectionName5}}/{{ObjectId5}}",
// "id": "t2",
// "body": {
// "{{FieldName1}}": "{{FieldName1Value7}}"
// },
// "headers": {
// "Content-Type": "application/json;odata=verbose",
// "Accept": "application/json;odata=verbose",
// "Prefer": "continue-on-error"
// }
// },
// {
// "method": "POST",
// "atomicityGroup": "g1",
// "url": "{{CollectionName5}}",
// "id": "t3",
// "body": {
// "{{FieldName6}}": "{{FieldName6Value2}}",
// "{{FieldName1}}": "{{FieldName1Value8}}"
// },
// "headers": {
// "Content-Type": "application/json;odata=verbose",
// "Accept": "application/json;odata=verbose",
// "Prefer": "continue-on-error"
// }
// }
// ]
// }
let json = CkoJsonObject()
json.UpdateString("requests[0].method", value: "POST")
json.UpdateString("requests[0].url", value: "{{CollectionName5}}")
json.UpdateString("requests[0].id", value: "t3")
json.UpdateString("requests[0].body.{{FieldName1}}", value: "{{FieldName1Value4}}")
json.UpdateString("requests[0].headers.Content-Type", value: "application/json;odata=verbose")
json.UpdateString("requests[0].headers.Accept", value: "application/json;odata=verbose")
json.UpdateString("requests[0].headers.Prefer", value: "continue-on-error")
json.UpdateString("requests[1].method", value: "PATCH")
json.UpdateString("requests[1].atomicityGroup", value: "g1")
json.UpdateString("requests[1].url", value: "{{CollectionName5}}/{{ObjectId5}}")
json.UpdateString("requests[1].id", value: "t2")
json.UpdateString("requests[1].body.{{FieldName1}}", value: "{{FieldName1Value7}}")
json.UpdateString("requests[1].headers.Content-Type", value: "application/json;odata=verbose")
json.UpdateString("requests[1].headers.Accept", value: "application/json;odata=verbose")
json.UpdateString("requests[1].headers.Prefer", value: "continue-on-error")
json.UpdateString("requests[2].method", value: "POST")
json.UpdateString("requests[2].atomicityGroup", value: "g1")
json.UpdateString("requests[2].url", value: "{{CollectionName5}}")
json.UpdateString("requests[2].id", value: "t3")
json.UpdateString("requests[2].body.{{FieldName6}}", value: "{{FieldName6Value2}}")
json.UpdateString("requests[2].body.{{FieldName1}}", value: "{{FieldName1Value8}}")
json.UpdateString("requests[2].headers.Content-Type", value: "application/json;odata=verbose")
json.UpdateString("requests[2].headers.Accept", value: "application/json;odata=verbose")
json.UpdateString("requests[2].headers.Prefer", value: "continue-on-error")
http.SetRequestHeader("Prefer", value: "continue-on-error")
http.SetRequestHeader("Content-Type", value: "application/json;odata=verbose;IEEE754Compatible=true")
http.SetRequestHeader("BPMCSRF", value: "{{BPMCSRF}}")
http.SetRequestHeader("Accept", value: "application/json")
http.SetRequestHeader("ForceUseSession", value: "true")
var resp: CkoHttpResponse? = http.PostJson3("https://myserver.com/0/odata/$batch", contentType: "application/json;odata=verbose;IEEE754Compatible=true", json: json)
if http.LastMethodSuccess == false {
print("\(http.LastErrorText)")
return
}
print("\(resp!.StatusCode.intValue)")
print("\(resp!.BodyStr)")
resp = nil
}
Curl Command
curl -X POST
-H "Content-Type: application/json;odata=verbose;IEEE754Compatible=true"
-H "Accept: application/json"
-H "BPMCSRF: {{BPMCSRF}}"
-H "Prefer: continue-on-error"
-H "ForceUseSession: true"
-d '{
"requests": [
{
"method": "POST",
"url": "{{CollectionName5}}",
"id": "t3",
"body": {
"{{FieldName1}}": "{{FieldName1Value4}}"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
"method": "PATCH",
"atomicityGroup": "g1",
"url": "{{CollectionName5}}/{{ObjectId5}}",
"id": "t2",
"body": {
"{{FieldName1}}": "{{FieldName1Value7}}"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
},
{
"method": "POST",
"atomicityGroup": "g1",
"url": "{{CollectionName5}}",
"id": "t3",
"body": {
"{{FieldName6}}": "{{FieldName6Value2}}",
"{{FieldName1}}": "{{FieldName1Value8}}"
},
"headers": {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Prefer": "continue-on-error"
}
}
]
}'
https://myserver.com/0/odata/$batch
Postman Collection Item JSON
{
"name": "$batch parameter (Content-Type: application/json and Prefer: continue-on-error)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json;odata=verbose;IEEE754Compatible=true"
},
{
"key": "Accept",
"type": "text",
"value": "application/json"
},
{
"key": "BPMCSRF",
"type": "text",
"value": "{{BPMCSRF}}"
},
{
"key": "Prefer",
"type": "text",
"value": "continue-on-error"
},
{
"key": "ForceUseSession",
"type": "text",
"value": "true"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n\t\"requests\": [\r\n\t{\r\n\t\t\"method\": \"POST\",\r\n\t\t\"url\": \"{{CollectionName5}}\",\r\n\t\t\"id\": \"t3\",\r\n\t\t\"body\": {\r\n\t\t\t\"{{FieldName1}}\": \"{{FieldName1Value4}}\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t},\r\n\t{\r\n\t\t\"method\": \"PATCH\",\r\n\t\t\"atomicityGroup\": \"g1\",\r\n\t\t\"url\": \"{{CollectionName5}}/{{ObjectId5}}\",\r\n\t\t\"id\": \"t2\",\r\n\t\t\"body\": {\r\n\t\t\t\"{{FieldName1}}\": \"{{FieldName1Value7}}\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t},\r\n\t{\r\n\t\t\"method\": \"POST\",\r\n\t\t\"atomicityGroup\": \"g1\",\r\n\t\t\"url\": \"{{CollectionName5}}\",\r\n\t\t\"id\": \"t3\",\r\n\t\t\"body\": {\r\n\t\t\t\"{{FieldName6}}\": \"{{FieldName6Value2}}\",\r\n\t\t\t\"{{FieldName1}}\": \"{{FieldName1Value8}}\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t}\r\n\t]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BaseURI}}/0/odata/$batch",
"host": [
"{{BaseURI}}"
],
"path": [
"0",
"odata",
"$batch"
]
},
"description": "Batch request with the same type of returned content without interrupting the execution of requests when the request is unsuccessful (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: application/json and Prefer headers",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json; odata=verbose; IEEE754Compatible=true"
},
{
"key": "Accept",
"type": "text",
"value": "application/json"
},
{
"key": "BPMCSRF",
"type": "text",
"value": "{{BPMCSRF}}"
},
{
"key": "Prefer",
"type": "text",
"value": "continue-on-error"
},
{
"key": "ForceUseSession",
"type": "text",
"value": "true"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n\t\"requests\": [\r\n\t{\r\n\t\t\"method\": \"POST\",\r\n\t\t\"url\": \"city\",\r\n\t\t\"id\": \"t3\",\r\n\t\t\"body\": {\r\n\t\t\t\"Name\": \"Burbank\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t},\r\n\t{\r\n\t\t\"method\": \"PATCH\",\r\n\t\t\"atomicityGroup\": \"g1\",\r\n\t\t\"url\": \"City/62f9bc01-57cf-4cc7-90bf-8672acc922e2\",\r\n\t\t\"id\": \"t2\",\r\n\t\t\"body\": {\r\n\t\t\t\"Name\": \"Indiana\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t},\r\n\t{\r\n\t\t\"method\": \"POST\",\r\n\t\t\"atomicityGroup\": \"g1\",\r\n\t\t\"url\": \"City\",\r\n\t\t\"id\": \"t3\",\r\n\t\t\"body\": {\r\n\t\t\t\"Id\": \"62f9bc01-57cf-4cc7-90bf-8672acc922a1\",\r\n\t\t\t\"Name\": \"Iowa\"\r\n\t\t},\r\n\t\t\"headers\": {\r\n\t\t\t\"Content-Type\": \"application/json;odata=verbose\",\r\n\t\t\t\"Accept\": \"application/json;odata=verbose\",\r\n\t\t\t\"Prefer\": \"continue-on-error\"\r\n\t\t}\r\n\t}\r\n\t]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://myserver.com/0/odata/$batch",
"protocol": "https",
"host": [
"myserver",
"com"
],
"path": [
"0",
"odata",
"$batch"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "text/html"
},
{
"key": "Server",
"value": "Microsoft-IIS/10.0"
},
{
"key": "Set-Cookie",
"value": "BPMSESSIONID=cni0cjy2ab2gxoq2p5jbafwc; path=/0; secure; HttpOnly"
},
{
"key": "X-Powered-By",
"value": "ASP.NET"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Date",
"value": "Mon, 18 May 2020 15:04:10 GMT"
},
{
"key": "Content-Length",
"value": "1233"
}
],
"cookie": [
],
"body": "{\n \"responses\": [\n {\n \"id\": \"t3\",\n \"status\": 201,\n \"headers\": {\n \"location\": \"https://myserver.com/0/odata/City(2f5e68f8-38bd-43c1-8e15-a2f13b0aa56a)\",\n \"content-type\": \"application/json; odata.metadata=minimal\",\n \"odata-version\": \"4.0\"\n },\n \"body\": {\n \"@odata.context\": \"https://myserver.com/0/odata/$metadata#City/$entity\",\n \"Id\": \"2f5e68f8-38bd-43c1-8e15-a2f13b0aa56a\",\n \"CreatedOn\": \"2020-05-18T18:06:50.7329808Z\",\n \"CreatedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\n \"ModifiedOn\": \"2020-05-18T18:06:50.7329808Z\",\n \"ModifiedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\n \"Name\": \"Burbank\",\n \"Description\": \"\",\n \"CountryId\": \"00000000-0000-0000-0000-000000000000\",\n \"RegionId\": \"00000000-0000-0000-0000-000000000000\",\n \"TimeZoneId\": \"00000000-0000-0000-0000-000000000000\",\n \"ProcessListeners\": 0\n }\n },\n {\n \"id\": \"t2\",\n \"atomicityGroup\": \"0c1c4019-b9fb-4fb3-8642-2d0660c4551a\",\n \"status\": 204,\n \"headers\": {\n \"odata-version\": \"4.0\"\n }\n },\n {\n \"id\": \"t3\",\n \"atomicityGroup\": \"0c1c4019-b9fb-4fb3-8642-2d0660c4551a\",\n \"status\": 201,\n \"headers\": {\n \"location\": \"https://myserver.com/0/odata/City(62f9bc01-57cf-4cc7-90bf-8672acc922a1)\",\n \"content-type\": \"application/json; odata.metadata=minimal\",\n \"odata-version\": \"4.0\"\n },\n \"body\": {\n \"@odata.context\": \"https://myserver.com/0/odata/$metadata#City/$entity\",\n \"Id\": \"62f9bc01-57cf-4cc7-90bf-8672acc922a1\",\n \"CreatedOn\": \"2020-05-18T18:06:50.7954775Z\",\n \"CreatedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\n \"ModifiedOn\": \"2020-05-18T18:06:50.7954775Z\",\n \"ModifiedById\": \"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\n \"Name\": \"Iowa\",\n \"Description\": \"\",\n \"CountryId\": \"00000000-0000-0000-0000-000000000000\",\n \"RegionId\": \"00000000-0000-0000-0000-000000000000\",\n \"TimeZoneId\": \"00000000-0000-0000-0000-000000000000\",\n \"ProcessListeners\": 0\n }\n }\n ]\n}"
}
]
}