Chilkat Online Tools

DataFlex / Creatio API / $batch parameter (Content-Type: application/json and Prefer: continue-on-error)

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1

    // 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

    // 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"
    //       }
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "requests[0].method" "POST" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].url" "{{CollectionName5}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].id" "t3" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].body.{{FieldName1}}" "{{FieldName1Value4}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].headers.Content-Type" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].headers.Accept" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[0].headers.Prefer" "continue-on-error" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].method" "PATCH" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].atomicityGroup" "g1" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].url" "{{CollectionName5}}/{{ObjectId5}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].id" "t2" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].body.{{FieldName1}}" "{{FieldName1Value7}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].headers.Content-Type" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].headers.Accept" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[1].headers.Prefer" "continue-on-error" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].method" "POST" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].atomicityGroup" "g1" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].url" "{{CollectionName5}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].id" "t3" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].body.{{FieldName6}}" "{{FieldName6Value2}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].body.{{FieldName1}}" "{{FieldName1Value8}}" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].headers.Content-Type" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].headers.Accept" "application/json;odata=verbose" To iSuccess
    Get ComUpdateString Of hoJson "requests[2].headers.Prefer" "continue-on-error" To iSuccess

    Send ComSetRequestHeader To hoHttp "Prefer" "continue-on-error"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json;odata=verbose;IEEE754Compatible=true"
    Send ComSetRequestHeader To hoHttp "BPMCSRF" "{{BPMCSRF}}"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"
    Send ComSetRequestHeader To hoHttp "ForceUseSession" "true"

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" "https://myserver.com/0/odata/$batch" vJson "application/json;odata=verbose;IEEE754Compatible=true" vResp To iSuccess
    If (iSuccess = 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


End_Procedure

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}"
    }
  ]
}