SQL Server / Creatio API / Modify object collection instance
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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "{{FieldName5}}": "{{FieldName5Value2}}"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '{{FieldName5}}', '{{FieldName5Value2}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'ForceUseSession', 'true'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'BPMCSRF', '{{BPMCSRF}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
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 @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://myserver.com/0/odata/Collection3(Id)', @sbRequestBody, 'utf-8', 'application/json', 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 @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode <> 204
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Response Body:'
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC @hr = sp_OADestroy @resp
PRINT 'Success.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X PATCH
-H "Accept: application/json"
-H "Content-Type: application/json"
-H "ForceUseSession: true"
-H "BPMCSRF: {{BPMCSRF}}"
-d '{
"{{FieldName5}}": "{{FieldName5Value2}}"
}'
https://myserver.com/0/odata/Collection3(Id)
Postman Collection Item JSON
{
"name": "Modify object collection instance",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PATCH",
"header": [
{
"key": "Accept",
"value": "application/json",
"type": "text"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "ForceUseSession",
"value": "true",
"type": "text"
},
{
"key": "BPMCSRF",
"value": "{{BPMCSRF}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"{{FieldName5}}\": \"{{FieldName5Value2}}\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BaseURI}}/0/odata/{{CollectionName3}}({{ObjectId1}})",
"host": [
"{{BaseURI}}"
],
"path": [
"0",
"odata",
"{{CollectionName3}}({{ObjectId1}})"
]
},
"description": "Request for modifying an object collection instance."
},
"response": [
{
"name": "[204] Modifies an object collection instance",
"originalRequest": {
"method": "PATCH",
"header": [
{
"key": "Accept",
"value": "application/json",
"type": "text"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "ForceUseSession",
"value": "true",
"type": "text"
},
{
"key": "BPMCSRF",
"value": "{{BPMCSRF}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"JobTitle\": \"Head of department\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://myserver.com/0/odata/Contact(c31c7862-fe33-4a13-9bbc-0943fa08fd02)",
"protocol": "https",
"host": [
"myserver",
"com"
],
"path": [
"0",
"odata",
"Contact(c31c7862-fe33-4a13-9bbc-0943fa08fd02)"
]
}
},
"status": "No Content",
"code": 204,
"_postman_previewlanguage": "html",
"header": [
{
"key": "Cache-Control",
"value": "private"
},
{
"key": "Content-Type",
"value": "text/html; charset=utf-8"
},
{
"key": "Server",
"value": "Microsoft-IIS/10.0"
},
{
"key": "X-Powered-By",
"value": "ASP.NET"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Date",
"value": "Fri, 06 Mar 2020 07:28:10 GMT"
},
{
"key": "Content-Length",
"value": "4949"
}
],
"cookie": [
],
"body": ""
}
]
}