SQL Server / Creatio API / $batch parameter (Content-Type: multipart/mixed)
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, '{"{{FieldName1}}": "{{FieldName1Value9}}"}' + 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, 'PATCH {{CollectionName5}}/{{ObjectId5}} 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, '{"{{FieldName1}}": "{{FieldName1Value10}}"}' + 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, 'DELETE {{CollectionName5}}/{{ObjectId5}} HTTP/1.1' + CHAR(10)
EXEC sp_OAMethod @sbRequestBody, 'Append', @success OUT, 'Content-ID: 3' + 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'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'multipart/mixed; boundary=batch_a685-9724-d873; IEEE754Compatible=true'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'ForceUseSession', 'true'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'BPMCSRF', '{{BPMCSRF}}'
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 "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
{"{{FieldName1}}": "{{FieldName1Value9}}"}
--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH {{CollectionName5}}/{{ObjectId5}} 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
{"{{FieldName1}}": "{{FieldName1Value10}}"}
--changeset_06da-d998-8e7e
Content-Type: application/http
Content-Transfer-Encoding: binary
DELETE {{CollectionName5}}/{{ObjectId5}} HTTP/1.1
Content-ID: 3
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Content-Type: application/json;odata=verbose'
https://myserver.com/0/odata/$batch
Postman Collection Item JSON
{
"name": "$batch parameter (Content-Type: multipart/mixed)",
"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": "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{\"{{FieldName1}}\": \"{{FieldName1Value9}}\"}\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPATCH {{CollectionName5}}/{{ObjectId5}} 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{\"{{FieldName1}}\": \"{{FieldName1Value10}}\"}\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nDELETE {{CollectionName5}}/{{ObjectId5}} HTTP/1.1\nContent-ID: 3\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose"
},
"url": {
"raw": "{{BaseURI}}/0/odata/$batch",
"host": [
"{{BaseURI}}"
],
"path": [
"0",
"odata",
"$batch"
]
},
"description": "Batch request with different types of returned content (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",
"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": "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{\"Name\": \"Gilbert\"}\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nPATCH City/62f9bc01-57cf-4cc7-90bf-8672acc922e2 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{\"Name\": \"Lincoln\"}\n\n--changeset_06da-d998-8e7e\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nDELETE City//62f9bc01-57cf-4cc7-90bf-8672acc922e2 HTTP/1.1\nContent-ID: 3\nAccept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1\nContent-Type: application/json;odata=verbose"
},
"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": "--batchresponse_e17aace9-5cbb-49bd-b7ad-f1be8cc8c9d8\r\nContent-Type: multipart/mixed; boundary=changesetresponse_a08c1df6-4b82-4a9b-be61-7ef4cc7b23ba\r\n\r\n--changesetresponse_a08c1df6-4b82-4a9b-be61-7ef4cc7b23ba\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 1\r\n\r\nHTTP/1.1 201 Created\r\nLocation: https://myserver.com/odata/City(fbd0565f-fa8a-4214-ae89-c976c5f3acb4)\r\nContent-Type: application/json; odata.metadata=minimal\r\nOData-Version: 4.0\r\n\r\n{\"@odata.context\":\"https://myserver.com/0/odata/$metadata#City/$entity\",\"Id\":\"fbd0565f-fa8a-4214-ae89-c976c5f3acb4\",\"CreatedOn\":\"2020-05-18T18:41:57.0917235Z\",\"CreatedById\":\"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\"ModifiedOn\":\"2020-05-18T18:41:57.0917235Z\",\"ModifiedById\":\"dad159f3-6c2d-446a-98d2-0f4d26662bbe\",\"Name\":\"Gilbert\",\"Description\":\"\",\"CountryId\":\"00000000-0000-0000-0000-000000000000\",\"RegionId\":\"00000000-0000-0000-0000-000000000000\",\"TimeZoneId\":\"00000000-0000-0000-0000-000000000000\",\"ProcessListeners\":0}\r\n--changesetresponse_a08c1df6-4b82-4a9b-be61-7ef4cc7b23ba\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 2\r\n\r\nHTTP/1.1 204 No Content\r\nOData-Version: 4.0\r\n\r\n\r\n--changesetresponse_a08c1df6-4b82-4a9b-be61-7ef4cc7b23ba\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 3\r\n\r\nHTTP/1.1 204 No Content\r\n\r\n\r\n--changesetresponse_a08c1df6-4b82-4a9b-be61-7ef4cc7b23ba--\r\n--batchresponse_e17aace9-5cbb-49bd-b7ad-f1be8cc8c9d8--\r\n"
}
]
}