Not updating requesters in loop

Hi Guys,

Hope your doing good. I have a requirement where need to iterate all requesters, update custom check value for that requester. in loop if i am trying update custom field check box it is not updating, but status coming as 200. but if i try same body in postman it is updating. Can you guys help me any other work around need to proceed.

This is body i am sending and using v2 API update requester
“custom_fields”: {
“custom_check”: true
}
Thanks in advance,
Tejasri Kalluri.

1 Like

Can anyone review this?

Hi @Tejasri_Kalluri,

The body for the request seems fine. Could you share a code snippet of the request you are making?

1 Like

As @sarfaraz_Mohammed mentioned, the code snippet of how the loop is performed and how the complete request is made is available, that would help you troubleshoot it further.

2 Likes

Hi @sarfaraz_Mohammed,

Thanks for your response, I am using this API first for requesters in Freshservice
https://artisinc.freshservice.com/api/v2/requesters?page=1&per_page=100
based upon this response iterating requesters and updating requester custom field
For updating requester using this API
https://artisinc.freshservice.com/api/v2/requesters/8004499825

Hi @Raviraj,
This is code using in forloop,
var headers = { “Authorization”: “Basic cmZDY0s1cGFRcGJPUmRqclg3aTo=” };
var options = { headers: headers };
var url = https://artisinc.freshservice.com/api/v2/requesters?page=${page}&per_page=100;
console.log(url)
$request.get(url, options).then(function (data) {
try {
var resp = JSON.parse(data.response);
for (var i = 0; i < resp.requesters.length; i++) {
if (resp.requesters[i].active && resp.requesters[i].custom_fields.custom_check !== null) {
if (resp.requesters[i].custom_fields.custom_check === false)
updateRequesterField(resp.requesters[i].id);
}
}
if (resp.requesters.length === 100) {
page = page + 1;
get_all_contacts(page);
}

    } catch (error) {
      console.log(error)

    }
  },
    function (error) {
      console.log("all contacts error")
      console.log(error);
    });

and this the update function api call

var headers = { "Authorization": "Basic cmZDY0s1cGFRcGJPUmRqclg3aTo=", 'Content-Type': 'application/json' };

  var body = {

    "custom_fields": {

      "custom_check": true

    }

  };

  var options = { headers: headers, body: JSON.stringify(body) };

  var url = `https://artisinc.freshservice.com/api/v2/requesters/${id}`;

  $request.get(url, options).then(function (d) {
    console.log(`Updated Requester- ${id} custom check box..................`)
  }, function (error) {
    console.log(error);
  });
1 Like

Hi @Tejasri_Kalluri

Thanks for sharing the code snippets.
In the request, you are trying to update the custom field. It is a PUT method and not a GET. Can you change that and let us know if it works?

3 Likes

Thanks, @sarfaraz_Mohammed, That was my mistake not to check method

2 Likes