SQL Server / Creatio API / $batch parameter (Content-Type: multipart/mixed and different changesets)
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '--batch_a685-9724-d873' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e7e' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '--changeset_06da-d998-8e7e' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: application/http' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Transfer-Encoding: binary' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'POST {{CollectionName5}} HTTP/1.1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-ID: 1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: application/json;odata=verbose' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '{"{{FieldName6}}": "{{FieldName6Value3}}", "{{FieldName1}}": "{{FieldName1Value11}}"}' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '--batch_a685-9724-d873' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: multipart/mixed; boundary=changeset_06da-d998-8e71' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '--changeset_06da-d998-8e71' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: application/http' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Transfer-Encoding: binary' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'POST {{CollectionName5}} HTTP/1.1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-ID: 2' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-Type: application/json;odata=verbose' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, '{"{{FieldName6}}": "{{FieldName6Value4}}", "{{FieldName1}}": "{{FieldName1Value12}}"}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'BPMCSRF', '{{BPMCSRF}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'ForceUseSession', 'true'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'https://myserver.com/0/odata/$batch', @sbRequestBody, 'utf-8', 'multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
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}"
}
]
}