Chilkat Online Tools

Objective-C / Creatio API / Modify a field value of object collection instance

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "{{FieldName8}}": "{{FieldName6Value6}}"
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"{{FieldName8}}" value: @"{{FieldName6Value6}}"];

[http SetRequestHeader: @"Content-Type" value: @"application/json; odata=verbose; IEEE754Compatible=true"];
[http SetRequestHeader: @"BPMCSRF" value: @"{{BPMCSRF}}"];
[http SetRequestHeader: @"Accept" value: @"application/json; odata=verbose"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"PATCH" url: @"https://myserver.com/0/odata/Collection3({{ObjectId8}})" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json; odata=verbose; IEEE754Compatible=true" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode != 204) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",resp.BodyStr);
    NSLog(@"%@",@"Failed.");

    return;
}

NSLog(@"%@",@"Success.");

Curl Command

curl -X PATCH
	-H "Accept: application/json; odata=verbose"
	-H "Content-Type: application/json; odata=verbose; IEEE754Compatible=true"
	-H "BPMCSRF: {{BPMCSRF}}"
	-d '{
    "{{FieldName8}}": "{{FieldName6Value6}}"
}'
https://myserver.com/0/odata/Collection3({{ObjectId8}})

Postman Collection Item JSON

{
  "name": "Modify a field value of 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; odata=verbose",
        "type": "text"
      },
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json; odata=verbose; IEEE754Compatible=true",
        "type": "text"
      },
      {
        "key": "BPMCSRF",
        "value": "{{BPMCSRF}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"{{FieldName8}}\": \"{{FieldName6Value6}}\"\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{BaseURI}}/0/odata/{{CollectionName3}}({{ObjectId8}})",
      "host": [
        "{{BaseURI}}"
      ],
      "path": [
        "0",
        "odata",
        "{{CollectionName3}}({{ObjectId8}})"
      ]
    },
    "description": "Request for modifying a field value of an object collection instance."
  },
  "response": [
    {
      "name": "[204] Modifies a field of object collection instance",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Accept",
            "value": "application/json; odata=verbose",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json; odata=verbose; IEEE754Compatible=true",
            "type": "text"
          },
          {
            "key": "BPMCSRF",
            "value": "{{BPMCSRF}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "file",
          "file": {
            "src": "/C:/Users/M.Kysla/Downloads/scr_NewContactPhoto.png"
          },
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://myserver.com/0/odata/Contact(4c63c8fa-467b-48a6-973f-b2069298404f)",
          "protocol": "https",
          "host": [
            "myserver",
            "com"
          ],
          "path": [
            "0",
            "odata",
            "Contact(4c63c8fa-467b-48a6-973f-b2069298404f)"
          ]
        }
      },
      "status": "No Content",
      "code": 204,
      "_postman_previewlanguage": "Text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}