Chilkat Online Tools

PureBasic / Zoho CRM REST APIs / Accounts

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://domain.com/crm/v2/Accounts",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "data": [
    ;     {
    ;       "Owner": {
    ;         "name": "Patricia Boyle",
    ;         "id": "738964000000291009",
    ;         "email": "patricia.ss@zylker.com"
    ;       },
    ;       "$currency_symbol": "Af",
    ;       "Account_Type": null,
    ;       "SIC_Code": null,
    ;       "Last_Activity_Time": "2021-05-07T06:19:49+00:00",
    ;       "Industry": null,
    ;       "Account_Site": null,
    ;       "$state": "save",
    ;       "$process_flow": false,
    ;       "Exchange_Rate": 1,
    ;       "Billing_Country": null,
    ;       "Currency": "AFN",
    ;       "id": "738964000002058030",
    ;       "$approved": true,
    ;       "$approval": {
    ;         "delegate": false,
    ;         "approve": false,
    ;         "reject": false,
    ;         "resubmit": false
    ;       },
    ;       "Billing_Street": null,
    ;       "Created_Time": "2021-04-21T08:53:58+00:00",
    ;       "$editable": true,
    ;       "Billing_Code": "1234",
    ;       "Shipping_City": null,
    ;       "Shipping_Country": null,
    ;       "Shipping_Code": null,
    ;       "Billing_City": null,
    ;       "Created_By": {
    ;         "name": "Patricia Boyle",
    ;         "id": "738964000000291009",
    ;         "email": "patricia.ss@zylker.com"
    ;       },
    ;       "Annual_Revenue": 1,
    ;       "Shipping_Street": null,
    ;       "territory_updated_time": null,
    ;       "Ownership": null,
    ;       "Description": null,
    ;       "Rating": null,
    ;       "Shipping_State": null,
    ;       "$review_process": {
    ;         "approve": false,
    ;         "reject": false,
    ;         "resubmit": false
    ;       },
    ;       "Website": "https://yaythisworked.com",
    ;       "Employees": null,
    ;       "Record_Image": null,
    ;       "Modified_By": {
    ;         "name": "Patricia Boyle",
    ;         "id": "738964000000291009",
    ;         "email": "patricia.ss@zylker.com"
    ;       },
    ;       "$review": null,
    ;       "Phone": null,
    ;       "Account_Name": "Villa Margarita",
    ;       "Account_Number": "0",
    ;       "Ticker_Symbol": null,
    ;       "Modified_Time": "2021-05-07T06:19:48+00:00",
    ;       "Territories": [
    ;         "South Zone"
    ;       ],
    ;       "$orchestration": false,
    ;       "Parent_Account": null,
    ;       "$in_merge": false,
    ;       "Billing_State": "Colorado",
    ;       "Tag": [
    ;       ],
    ;       "Fax": null,
    ;       "$approval_state": "approved"
    ;     }
    ;   ],
    ;   "info": {
    ;     "per_page": 200,
    ;     "count": 1,
    ;     "page": 1,
    ;     "more_records": false
    ;   }
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    Name.s
    Id.s
    v_Email.s
    Scurrency_symbol.s
    Account_Type.s
    SIC_Code.s
    Last_Activity_Time.s
    Industry.s
    Account_Site.s
    Sstate.s
    Sprocess_flow.i
    Exchange_Rate.i
    Billing_Country.s
    v_Currency.s
    id.s
    Sapproved.i
    Delegate.i
    Approve.i
    Reject.i
    Resubmit.i
    Billing_Street.s
    Created_Time.s
    Seditable.i
    Billing_Code.s
    Shipping_City.s
    Shipping_Country.s
    Shipping_Code.s
    Billing_City.s
    Created_ByName.s
    Created_ById.s
    Created_ByEmail.s
    Annual_Revenue.i
    Shipping_Street.s
    territory_updated_time.s
    Ownership.s
    Description.s
    Rating.s
    Shipping_State.s
    Sreview_processApprove.i
    Sreview_processReject.i
    Sreview_processResubmit.i
    Website.s
    Employees.s
    Record_Image.s
    Modified_ByName.s
    Modified_ById.s
    Modified_ByEmail.s
    Sreview.s
    Phone.s
    Account_Name.s
    Account_Number.s
    Ticker_Symbol.s
    Modified_Time.s
    Sorchestration.i
    Parent_Account.s
    Sin_merge.i
    Billing_State.s
    Fax.s
    Sapproval_state.s
    j.i
    count_j.i
    strVal.s

    Per_page.i = CkJsonObject::ckIntOf(jResp,"info.per_page")
    Count.i = CkJsonObject::ckIntOf(jResp,"info.count")
    Page.i = CkJsonObject::ckIntOf(jResp,"info.page")
    More_records.i = CkJsonObject::ckBoolOf(jResp,"info.more_records")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"data")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        Name = CkJsonObject::ckStringOf(jResp,"data[i].Owner.name")
        Id = CkJsonObject::ckStringOf(jResp,"data[i].Owner.id")
        v_Email = CkJsonObject::ckStringOf(jResp,"data[i].Owner.email")
        Scurrency_symbol = CkJsonObject::ckStringOf(jResp,"data[i].$currency_symbol")
        Account_Type = CkJsonObject::ckStringOf(jResp,"data[i].Account_Type")
        SIC_Code = CkJsonObject::ckStringOf(jResp,"data[i].SIC_Code")
        Last_Activity_Time = CkJsonObject::ckStringOf(jResp,"data[i].Last_Activity_Time")
        Industry = CkJsonObject::ckStringOf(jResp,"data[i].Industry")
        Account_Site = CkJsonObject::ckStringOf(jResp,"data[i].Account_Site")
        Sstate = CkJsonObject::ckStringOf(jResp,"data[i].$state")
        Sprocess_flow = CkJsonObject::ckBoolOf(jResp,"data[i].$process_flow")
        Exchange_Rate = CkJsonObject::ckIntOf(jResp,"data[i].Exchange_Rate")
        Billing_Country = CkJsonObject::ckStringOf(jResp,"data[i].Billing_Country")
        v_Currency = CkJsonObject::ckStringOf(jResp,"data[i].Currency")
        id = CkJsonObject::ckStringOf(jResp,"data[i].id")
        Sapproved = CkJsonObject::ckBoolOf(jResp,"data[i].$approved")
        Delegate = CkJsonObject::ckBoolOf(jResp,"data[i].$approval.delegate")
        Approve = CkJsonObject::ckBoolOf(jResp,"data[i].$approval.approve")
        Reject = CkJsonObject::ckBoolOf(jResp,"data[i].$approval.reject")
        Resubmit = CkJsonObject::ckBoolOf(jResp,"data[i].$approval.resubmit")
        Billing_Street = CkJsonObject::ckStringOf(jResp,"data[i].Billing_Street")
        Created_Time = CkJsonObject::ckStringOf(jResp,"data[i].Created_Time")
        Seditable = CkJsonObject::ckBoolOf(jResp,"data[i].$editable")
        Billing_Code = CkJsonObject::ckStringOf(jResp,"data[i].Billing_Code")
        Shipping_City = CkJsonObject::ckStringOf(jResp,"data[i].Shipping_City")
        Shipping_Country = CkJsonObject::ckStringOf(jResp,"data[i].Shipping_Country")
        Shipping_Code = CkJsonObject::ckStringOf(jResp,"data[i].Shipping_Code")
        Billing_City = CkJsonObject::ckStringOf(jResp,"data[i].Billing_City")
        Created_ByName = CkJsonObject::ckStringOf(jResp,"data[i].Created_By.name")
        Created_ById = CkJsonObject::ckStringOf(jResp,"data[i].Created_By.id")
        Created_ByEmail = CkJsonObject::ckStringOf(jResp,"data[i].Created_By.email")
        Annual_Revenue = CkJsonObject::ckIntOf(jResp,"data[i].Annual_Revenue")
        Shipping_Street = CkJsonObject::ckStringOf(jResp,"data[i].Shipping_Street")
        territory_updated_time = CkJsonObject::ckStringOf(jResp,"data[i].territory_updated_time")
        Ownership = CkJsonObject::ckStringOf(jResp,"data[i].Ownership")
        Description = CkJsonObject::ckStringOf(jResp,"data[i].Description")
        Rating = CkJsonObject::ckStringOf(jResp,"data[i].Rating")
        Shipping_State = CkJsonObject::ckStringOf(jResp,"data[i].Shipping_State")
        Sreview_processApprove = CkJsonObject::ckBoolOf(jResp,"data[i].$review_process.approve")
        Sreview_processReject = CkJsonObject::ckBoolOf(jResp,"data[i].$review_process.reject")
        Sreview_processResubmit = CkJsonObject::ckBoolOf(jResp,"data[i].$review_process.resubmit")
        Website = CkJsonObject::ckStringOf(jResp,"data[i].Website")
        Employees = CkJsonObject::ckStringOf(jResp,"data[i].Employees")
        Record_Image = CkJsonObject::ckStringOf(jResp,"data[i].Record_Image")
        Modified_ByName = CkJsonObject::ckStringOf(jResp,"data[i].Modified_By.name")
        Modified_ById = CkJsonObject::ckStringOf(jResp,"data[i].Modified_By.id")
        Modified_ByEmail = CkJsonObject::ckStringOf(jResp,"data[i].Modified_By.email")
        Sreview = CkJsonObject::ckStringOf(jResp,"data[i].$review")
        Phone = CkJsonObject::ckStringOf(jResp,"data[i].Phone")
        Account_Name = CkJsonObject::ckStringOf(jResp,"data[i].Account_Name")
        Account_Number = CkJsonObject::ckStringOf(jResp,"data[i].Account_Number")
        Ticker_Symbol = CkJsonObject::ckStringOf(jResp,"data[i].Ticker_Symbol")
        Modified_Time = CkJsonObject::ckStringOf(jResp,"data[i].Modified_Time")
        Sorchestration = CkJsonObject::ckBoolOf(jResp,"data[i].$orchestration")
        Parent_Account = CkJsonObject::ckStringOf(jResp,"data[i].Parent_Account")
        Sin_merge = CkJsonObject::ckBoolOf(jResp,"data[i].$in_merge")
        Billing_State = CkJsonObject::ckStringOf(jResp,"data[i].Billing_State")
        Fax = CkJsonObject::ckStringOf(jResp,"data[i].Fax")
        Sapproval_state = CkJsonObject::ckStringOf(jResp,"data[i].$approval_state")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"data[i].Territories")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"data[i].Territories[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"data[i].Tag")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/crm/v2/Accounts

Postman Collection Item JSON

{
  "name": "Accounts",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{api-domain}}/crm/v2/Accounts",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "Accounts"
      ]
    },
    "description": "To get the list of available records in the Accounts module."
  },
  "response": [
    {
      "name": "P8: territory_id",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Accounts?territory_id=738964000001977355",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Accounts"
          ],
          "query": [
            {
              "key": "territory_id",
              "value": "738964000001977355"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 12:37:14 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-11T12:57:36+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4023320"
        },
        {
          "key": "clientsubVersion",
          "value": "4d8b6ee4f7d1d284c930a4e807480c5c"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": [\n        {\n            \"Owner\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$currency_symbol\": \"Af\",\n            \"Account_Type\": null,\n            \"SIC_Code\": null,\n            \"Last_Activity_Time\": \"2021-05-07T06:19:49+00:00\",\n            \"Industry\": null,\n            \"Account_Site\": null,\n            \"$state\": \"save\",\n            \"$process_flow\": false,\n            \"Exchange_Rate\": 1,\n            \"Billing_Country\": null,\n            \"Currency\": \"AFN\",\n            \"id\": \"738964000002058030\",\n            \"$approved\": true,\n            \"$approval\": {\n                \"delegate\": false,\n                \"approve\": false,\n                \"reject\": false,\n                \"resubmit\": false\n            },\n            \"Billing_Street\": null,\n            \"Created_Time\": \"2021-04-21T08:53:58+00:00\",\n            \"$editable\": true,\n            \"Billing_Code\": \"1234\",\n            \"Shipping_City\": null,\n            \"Shipping_Country\": null,\n            \"Shipping_Code\": null,\n            \"Billing_City\": null,\n            \"Created_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"Annual_Revenue\": 1,\n            \"Shipping_Street\": null,\n            \"territory_updated_time\": null,\n            \"Ownership\": null,\n            \"Description\": null,\n            \"Rating\": null,\n            \"Shipping_State\": null,\n            \"$review_process\": {\n                \"approve\": false,\n                \"reject\": false,\n                \"resubmit\": false\n            },\n            \"Website\": \"https://yaythisworked.com\",\n            \"Employees\": null,\n            \"Record_Image\": null,\n            \"Modified_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$review\": null,\n            \"Phone\": null,\n            \"Account_Name\": \"Villa Margarita\",\n            \"Account_Number\": \"0\",\n            \"Ticker_Symbol\": null,\n            \"Modified_Time\": \"2021-05-07T06:19:48+00:00\",\n            \"Territories\": [\n                \"South Zone\"\n            ],\n            \"$orchestration\": false,\n            \"Parent_Account\": null,\n            \"$in_merge\": false,\n            \"Billing_State\": \"Colorado\",\n            \"Tag\": [],\n            \"Fax\": null,\n            \"$approval_state\": \"approved\"\n        }\n    ],\n    \"info\": {\n        \"per_page\": 200,\n        \"count\": 1,\n        \"page\": 1,\n        \"more_records\": false\n    }\n}"
    },
    {
      "name": "P9: include_child",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Accounts?territory_id=738964000001977355&include_child=true",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Accounts"
          ],
          "query": [
            {
              "key": "territory_id",
              "value": "738964000001977355"
            },
            {
              "key": "include_child",
              "value": "true"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Tue, 11 May 2021 12:37:35 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-11T12:57:36+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4023320"
        },
        {
          "key": "clientsubVersion",
          "value": "4d8b6ee4f7d1d284c930a4e807480c5c"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": [\n        {\n            \"Owner\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$currency_symbol\": \"Af\",\n            \"Account_Type\": null,\n            \"SIC_Code\": null,\n            \"Last_Activity_Time\": \"2021-05-07T06:19:49+00:00\",\n            \"Industry\": null,\n            \"Account_Site\": null,\n            \"$state\": \"save\",\n            \"$process_flow\": false,\n            \"Exchange_Rate\": 1,\n            \"Billing_Country\": null,\n            \"Currency\": \"AFN\",\n            \"id\": \"738964000002058030\",\n            \"$approved\": true,\n            \"$approval\": {\n                \"delegate\": false,\n                \"approve\": false,\n                \"reject\": false,\n                \"resubmit\": false\n            },\n            \"Billing_Street\": null,\n            \"Created_Time\": \"2021-04-21T08:53:58+00:00\",\n            \"$editable\": true,\n            \"Billing_Code\": \"1234\",\n            \"Shipping_City\": null,\n            \"Shipping_Country\": null,\n            \"Shipping_Code\": null,\n            \"Billing_City\": null,\n            \"Created_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"Annual_Revenue\": 1,\n            \"Shipping_Street\": null,\n            \"territory_updated_time\": null,\n            \"Ownership\": null,\n            \"Description\": null,\n            \"Rating\": null,\n            \"Shipping_State\": null,\n            \"$review_process\": {\n                \"approve\": false,\n                \"reject\": false,\n                \"resubmit\": false\n            },\n            \"Website\": \"https://yaythisworked.com\",\n            \"Employees\": null,\n            \"Record_Image\": null,\n            \"Modified_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"738964000000291009\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$review\": null,\n            \"Phone\": null,\n            \"Account_Name\": \"Villa Margarita\",\n            \"Account_Number\": \"0\",\n            \"Ticker_Symbol\": null,\n            \"Modified_Time\": \"2021-05-07T06:19:48+00:00\",\n            \"Territories\": [\n                \"South Zone\"\n            ],\n            \"$orchestration\": false,\n            \"Parent_Account\": null,\n            \"$in_merge\": false,\n            \"Billing_State\": \"Colorado\",\n            \"Tag\": [],\n            \"Fax\": null,\n            \"$approval_state\": \"approved\"\n        }\n    ],\n    \"info\": {\n        \"per_page\": 200,\n        \"count\": 1,\n        \"page\": 1,\n        \"more_records\": false\n    }\n}"
    }
  ]
}