Chilkat Online Tools

Go / Zoho CRM REST APIs / Leads

Back to Collection Items

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

    http := chilkat.NewHttp()
    var success bool

    // Adds the "Authorization: Bearer <access_token>" header.
    http.SetAuthToken("<access_token>")

    resp := http.QuickRequest("POST","Lead")
    if http.LastMethodSuccess() == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        return
    }

    sbResponseBody := chilkat.NewStringBuilder()
    resp.GetBodySb(sbResponseBody)

    jResp := chilkat.NewJsonObject()
    jResp.LoadSb(sbResponseBody)
    jResp.SetEmitCompact(false)

    fmt.Println("Response Body:")
    fmt.Println(*jResp.Emit())

    respStatusCode := resp.StatusCode()
    fmt.Println("Response Status Code = ", respStatusCode)
    if respStatusCode >= 400 {
        fmt.Println("Response Header:")
        fmt.Println(resp.Header())
        fmt.Println("Failed.")
        resp.DisposeHttpResponse()
        http.DisposeHttp()
        sbResponseBody.DisposeStringBuilder()
        jResp.DisposeJsonObject()
        return
    }

    resp.DisposeHttpResponse()

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

    // {
    //   "data": [
    //     {
    //       "code": "SUCCESS",
    //       "details": {
    //         "id": "738964000002131264",
    //         "tags": [
    //           "Tag1"
    //         ]
    //       },
    //       "message": "tags updated successfully",
    //       "status": "success"
    //     }
    //   ],
    //   "wf_scheduler": false,
    //   "success_count": "1",
    //   "locked_count": "0"
    // }

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

    var code *string = new(string)
    var Id *string = new(string)
    var message *string = new(string)
    var status *string = new(string)
    var j int
    var count_j int
    var strVal *string = new(string)

    wf_scheduler := jResp.BoolOf("wf_scheduler")
    success_count := jResp.StringOf("success_count")
    locked_count := jResp.StringOf("locked_count")
    i := 0
    count_i := jResp.SizeOfArray("data")
    for i < count_i {
        jResp.SetI(i)
        code = jResp.StringOf("data[i].code")
        Id = jResp.StringOf("data[i].details.id")
        message = jResp.StringOf("data[i].message")
        status = jResp.StringOf("data[i].status")
        j = 0
        count_j = jResp.SizeOfArray("data[i].details.tags")
        for j < count_j {
            jResp.SetJ(j)
            strVal = jResp.StringOf("data[i].details.tags[j]")
            j = j + 1
        }

        i = i + 1
    }


    http.DisposeHttp()
    sbResponseBody.DisposeStringBuilder()
    jResp.DisposeJsonObject()

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
https://domain.com/crm/v2/Leads/actions/add_tags?ids={{record_id1,record_id2}}&tag_names=important,Nurturing Lead

Postman Collection Item JSON

{
  "name": "Leads",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "url": {
      "raw": "{{api-domain}}/crm/v2/Leads/actions/add_tags?ids={{record_id1,record_id2}}&tag_names=important,Nurturing Lead",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "Leads",
        "actions",
        "add_tags"
      ],
      "query": [
        {
          "key": "ids",
          "value": "{{record_id1,record_id2}}"
        },
        {
          "key": "tag_names",
          "value": "important,Nurturing Lead"
        }
      ]
    },
    "description": "To add tags to records."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/actions/add_tags?ids=738964000002131264&tag_names=Tag1",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "actions",
            "add_tags"
          ],
          "query": [
            {
              "key": "ids",
              "value": "738964000002131264"
            },
            {
              "key": "tag_names",
              "value": "Tag1"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:42:31 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "200"
        },
        {
          "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-12T07:15:06+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": [\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {\n                \"id\": \"738964000002131264\",\n                \"tags\": [\n                    \"Tag1\"\n                ]\n            },\n            \"message\": \"tags updated successfully\",\n            \"status\": \"success\"\n        }\n    ],\n    \"wf_scheduler\": false,\n    \"success_count\": \"1\",\n    \"locked_count\": \"0\"\n}"
    },
    {
      "name": "INVALID_MODULE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Lead/actions/add_tags?ids=738964000002131264&tag_names=Tag1",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Lead",
            "actions",
            "add_tags"
          ],
          "query": [
            {
              "key": "ids",
              "value": "738964000002131264"
            },
            {
              "key": "tag_names",
              "value": "Tag1"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:42:51 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "110"
        },
        {
          "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-12T07:15:06+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_MODULE\",\n    \"details\": {},\n    \"message\": \"the module name given seems to be invalid\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/actions/add_tagsids=738964000002131264&tag_names=Tag1",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "actions",
            "add_tagsids=738964000002131264&tag_names=Tag1"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:44:13 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "131"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_URL_PATTERN\",\n    \"details\": {},\n    \"message\": \"Please check if the URL trying to access is a correct one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_REQUEST_METHOD",
      "originalRequest": {
        "method": "COPY",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/actions/add_tags?ids=738964000002131264&tag_names=Tag1",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "actions",
            "add_tags"
          ],
          "query": [
            {
              "key": "ids",
              "value": "738964000002131264"
            },
            {
              "key": "tag_names",
              "value": "Tag1"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:44:37 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "124"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_REQUEST_METHOD\",\n    \"details\": {},\n    \"message\": \"The http request method type is not a valid one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "AUTHENTICATION_FAILURE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/actions/add_tags?ids=738964000002131264&tag_names=Tag1",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "actions",
            "add_tags"
          ],
          "query": [
            {
              "key": "ids",
              "value": "738964000002131264"
            },
            {
              "key": "tag_names",
              "value": "Tag1"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:44:54 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "98"
        },
        {
          "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-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"AUTHENTICATION_FAILURE\",\n    \"details\": {},\n    \"message\": \"Authentication failed\",\n    \"status\": \"error\"\n}"
    }
  ]
}