Chilkat Online Tools

Swift / Creatio API / Add object collection instance

Back to Collection Items

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

    let http = CkoHttp()
    var success: Bool

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

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

    // {
    //   "{{FieldName1}}": "{{FieldName1Value3}}",
    //   "{{FieldName5}}": "{{FieldName5Value1}}"
    // }

    let json = CkoJsonObject()
    json.UpdateString("{{FieldName1}}", value: "{{FieldName1Value3}}")
    json.UpdateString("{{FieldName5}}", value: "{{FieldName5Value1}}")

    http.SetRequestHeader("Content-Type", value: "application/json")
    http.SetRequestHeader("ForceUseSession", value: "true")
    http.SetRequestHeader("BPMCSRF", value: "{{BPMCSRF}}")
    http.SetRequestHeader("Accept", value: "application/json")

    var resp: CkoHttpResponse? = http.PostJson3("https://myserver.com/0/odata/Collection3", contentType: "application/json", json: json)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	-H "Accept: application/json"
	-H "Content-Type: application/json"
	-H "ForceUseSession: true"
	-H "BPMCSRF: {{BPMCSRF}}"
	-d '{
    "{{FieldName1}}": "{{FieldName1Value3}}",
    "{{FieldName5}}": "{{FieldName5Value1}}"
}'
https://myserver.com/0/odata/Collection3

Postman Collection Item JSON

{
  "name": "Add object collection instance",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "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    \"{{FieldName1}}\": \"{{FieldName1Value3}}\",\n    \"{{FieldName5}}\": \"{{FieldName5Value1}}\"\n}\n",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{BaseURI}}/0/odata/{{CollectionName3}}",
      "host": [
        "{{BaseURI}}"
      ],
      "path": [
        "0",
        "odata",
        "{{CollectionName3}}"
      ]
    },
    "description": "Request for adding an object collection instance."
  },
  "response": [
    {
      "name": "[201] Adds an object collection instance",
      "originalRequest": {
        "method": "POST",
        "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    \"Name\": \"New User\",\n    \"JobTitle\": \"Developer\"\n}\n",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://myserver.com/0/odata/Contact",
          "protocol": "https",
          "host": [
            "myserver",
            "com"
          ],
          "path": [
            "0",
            "odata",
            "Contact"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_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": "Set-Cookie",
          "value": ".ASPXAUTH=66EFC86548FA6369546D9D4ADF6ED9990C53E405E9C1150A87C3F9B6CFC37B1DB0FC39FE110AF111A5B10B81C69563797DB518E8CF1F560B2F1C10E1D7E1EC7CBC538FE8CBD6F914741204BE5D7870B7F84EF3F156F8B6A76360EA1A7300354EA6CB2A5EB32EC9D49F130B0BB890305C82C375721048BC2F5D6220E89FE29B1423DA1BC4E62C30110AA0294ED9E4D5FCCE70E1A29EBA169F4519B58C583C308E377D6F0013391E54CF4E5D1934DF61E84067AC1EE251B58CD1F7B5A8D6066EAF56FE4E913D16A7E26934F4C88A95F6623545925780441F6B06C258C3E17AFFDF4F2DDF5C4075231860DD4778A15A149A791FE50B455F7E9DF22A95A6A7AB079CC4DD51AA01D7FE875A05AABB721627ED3B61277F4E5B4C5B363FA9288EF769E8F54424642743442C369EC67AC4A0345A83AB4A7FAAFDA2AE05B353FC1E2DFD8AA00312131A86C5A432BD0B5A0E77EEE1BAF9F5815F72614BE4CEBF7F12114F7D35657643; path=/; HttpOnly; SameSite=Lax"
        },
        {
          "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:01:22 GMT"
        },
        {
          "key": "Content-Length",
          "value": "4873"
        }
      ],
      "cookie": [
      ],
      "body": "{\r\n    \"@odata.context\": \"https://myserver.com/0/odata/$metadata#Contact/$entity\",\r\n    \"Id\": \"3d364a68-0afb-4938-8cb5-679d708091ef\",\r\n    \"Name\": \"New User\",\r\n    \"OwnerId\": \"410006e1-ca4e-4502-a9ec-e54d922d2c00\",\r\n    \"CreatedOn\": \"2020-02-27T08:05:55.2368355Z\",\r\n    \"CreatedById\": \"410006e1-ca4e-4502-a9ec-e54d922d2c00\",\r\n    \"ModifiedOn\": \"2020-02-27T08:05:55.2368355Z\",\r\n    \"ModifiedById\": \"410006e1-ca4e-4502-a9ec-e54d922d2c00\",\r\n    \"ProcessListeners\": 0,\r\n    \"Dear\": \"\",\r\n    \"SalutationTypeId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"GenderId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"AccountId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"DecisionRoleId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"TypeId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"JobId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"JobTitle\": \"Developer\",\r\n    \"DepartmentId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"BirthDate\": \"0001-01-01T00:00:00Z\",\r\n    \"Phone\": \"\",\r\n    \"MobilePhone\": \"\",\r\n    \"HomePhone\": \"\",\r\n    \"Skype\": \"\",\r\n    \"Email\": \"\",\r\n    \"AddressTypeId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"Address\": \"\",\r\n    \"CityId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"RegionId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"Zip\": \"\",\r\n    \"CountryId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"DoNotUseEmail\": false,\r\n    \"DoNotUseCall\": false,\r\n    \"DoNotUseFax\": false,\r\n    \"DoNotUseSms\": false,\r\n    \"DoNotUseMail\": false,\r\n    \"Notes\": \"\",\r\n    \"Facebook\": \"\",\r\n    \"LinkedIn\": \"\",\r\n    \"Twitter\": \"\",\r\n    \"FacebookId\": \"\",\r\n    \"LinkedInId\": \"\",\r\n    \"TwitterId\": \"\",\r\n    \"TwitterAFDAId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"FacebookAFDAId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"LinkedInAFDAId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"PhotoId\": \"00000000-0000-0000-0000-000000000000\",\r\n    \"GPSN\": \"\",\r\n    \"GPSE\": \"\",\r\n    \"Surname\": \"User\",\r\n    \"GivenName\": \"New\",\r\n    \"MiddleName\": \"\",\r\n    \"Confirmed\": true,\r\n    \"IsNonActualEmail\": false,\r\n    \"Completeness\": 0,\r\n    \"LanguageId\": \"6ebc31fa-ee6c-48e9-81bf-8003ac03b019\",\r\n    \"Age\": 0\r\n}\r\n\r\n"
    }
  ]
}