Custom Ticket Fields not Updating using ZAFClient "client.request" | Community
Skip to main content

Custom Ticket Fields not Updating using ZAFClient "client.request"

  • June 1, 2024
  • 2 replies
  • 0 views

Hi Team,

 

I've created an app in Zendesk and cant seem to update several custom ticket fields on a specific ticket.

Using ZAfclient - I can easily add a new comment but if I try to update a custom ticket field, the request is sent with a response but no change applied.

 

  let responseDetails: any;


 

  const dataToLoad = {

    "ticket": {

      "comment": {

        "body": `Worker: ${callRecordingInfo.callSID}

                 Recording SID: ${callRecordingInfo.recordingID}

                 Recording URL: ${callRecordingInfo.recordingLink}`,

        "public": false

      },

      "custom_fields": [

        { "id": 9856193510799, "value": callRecordingInfo.callSID},

        { "id": 9882996513935, "value": callRecordingInfo.recordingID},

        { "id": 9864797906191, "value": callRecordingInfo.recordingLink}

      ],

    }

  }

 

  const settings = {

    url: `/api/v2/tickets/${ticketId}`,

    type: 'PUT',

    data: dataToLoad,

    dataType: 'json',

  };

 

  await client.request(settings).then(

    (data: any) => responseDetails = data

  ).catch((error: any) => responseDetails = error)

    ;

  return responseDetails

 

Please help.

 

Gary

 

 

2 replies

  • June 3, 2024

Hello @gary19 
Here is a revised version of your code with some adjustments:

let responseDetails;

const dataToLoad = {
 "ticket": {
   "comment": {
     "body": `Worker: ${callRecordingInfo.callSID}\nRecording SID: ${callRecordingInfo.recordingID}\nRecording URL: ${callRecordingInfo.recordingLink}`,
     "public": false
   },
   "custom_fields": [
     { "id": 9856193510799, "value": callRecordingInfo.callSID },
     { "id": 9882996513935, "value": callRecordingInfo.recordingID },
     { "id": 9864797906191, "value": callRecordingInfo.recordingLink }
   ]
 }
};

const settings = {
 url: `/api/v2/tickets/${ticketId}`,
 type: 'PUT',
 contentType: 'application/json',
 data: JSON.stringify(dataToLoad),
 dataType: 'json'
};

await client.request(settings).then(
 (data) => responseDetails = data
).catch((error) => responseDetails = error);

return responseDetails;
 

I've replaced the multiline string with newline characters (\n) for better formatting, set contentType: 'application/json' to ensure the request is sent as JSON. and used JSON.stringify(dataToLoad) to ensure the data is properly formatted as a JSON string.


Greg29
  • June 3, 2024

Hi Gary!

Could you let me know the ticket number that you're having an issue with? I see that there are a lot of successful updates in your account, so it will help me narrow the issue down if I can know which ticket to focus on.