Api is not returning expected object in response in code

Hi All,

I am having reqirement to check no.of childs created to service request.For that i am using the following API https://freshservice domain/api/v2/tickets/ticketId?include=related_tickets.
If i am creating one child then in backend logs i am getting related obj as { child_ids: [ 1239 ] } but if i am creating more than one childs i am getting empty object in backend logs. can you check and help me to continue my work.

FYI i am providing the screen recording here.
Vidyard Recording?

I tried in postman in postman i am getting correct response i am attaching screen shot here.

And my code is here.

var url = `https://${FS_domain}/api/v2/tickets/${ticket_id}?include=related_tickets`;
 var headers = {
"Authorization": `Basic <%= encode(iparam.api) %>`
var options = {
headers: headers
$request.get(url, options).then(function (data) {
  var relTick_data = JSON.parse(data.response);
  // console.log(relTick_data);
  var ticketId = relTick_data.ticket.id;
console.log("Ticket id------>"+ticketId);
var dataObj = relTick_data.ticket.related_tickets;
console.log("Releated ticket obj");
}, function (error) {
console.log("i am in error block");

@Tipuranjali Since the API is working fine in Postman, couldn’t come to a concussion on where the problem is.

Could you hard-code all the variables in the API request except for Auth and print the whole response and share it here to help you with troubleshooting the code better? This will help analyze where it’s going wrong and narrow down the issue.

hi @Tipuranjali,

Hope you are well :slight_smile:

almost in all scenarios the response you get in postman and using request will be the same, I am not sure what might cause an issue like this,
could you please Stringify and print the entire response object and check if it has the related tickets array?

also, does this error occur in local testing or as a custom app, or in both scenarios?

Stay Safe :slight_smile:

Hello guys,

I also checked into this issue and this is occurring very abnormally. For example, if I tried to create a service request with 3 children and calling the Freshservice API(/api/v2/tickets/[id]?include=related_tickets) from the code and the response of related tickets info sometimes it’s receiving correctly and sometimes its returning an empty object. If needed I can show over the zoom call for better understanding purposes.