API to update a service request in Freshservice

Hi Folks,
I am having requirement to update a custom field of Service Request in freshservice portal. I tried this rest api through postman(https://{domain.freshservice.com}/api/v2/tickets/{ticketId}) i am getting 200 status.

But if i am trying the same thing through code i am getting method not allowed error.

FYI i am adding my code snippet here.
var url = https://${FS_domain}/api/v2/tickets/${ticketId};
var headers = {
“Authorization”: Basic <%= encode(iparam.api) %>,
“Content-Type”: “application/json”
};
var body = {
“description”:“i am anjali”,
“type”:“Incident”,
“custom_fields”:{
“user_id”:UserValue
}
};
var options = {
headers: headers,
body: JSON.stringify(body)
};
$request.put(url, options).then(function (data) {
console.log(data);
}, function (error) {
console.log(error);
});

Thanks,
Tipuranjali.

Hi @Tipuranjali,

Hope you are doing well,

The reason you get this error because $request.put is not a valid HTTP method in terms of Request API, Could you please try the ($request.post) method and let us know if you still get the error?

Hope this helps!

Stay Safe :slight_smile:

Hi @velmurugan,

Thanks for contributing your answer! And I am doing well,hope the same with you.

As you mentioned i tried with post also($request.post) through code but still i am facing issue “Method not allowed”. But in postman i am able to update custom fields successfully using “put” method.

FYI i am uploading the issue i am facing.

Thanks,
Tipuranjali.

@Tipuranjali,

Could you check if the endpoint is correct using a console.log() or in the networks tab of the browser, there could be a possibility that ${ticketId} is maybe null/empty and it’s trying to post to api/v2/tickets/ which only supports GET

if the endpoint is correct, please send us the sample payload and the endpoint. So, I can try from my end

Hi @velmurugan,

Could you please let me know how to update a Service Request custom field.

Thanks,
Tipuranjali.

Hello,
Can anyone help me how to update service request custom field.

Thanks,
Tipuranjali.

Hey @Tipuranjali

Apologies for overlooking this thread
I hope this issue is resolved, if the issue isn’t resolved, could you please share the code with is to investigate further?

You could also share your solution for this issue if it’s resolved for the benefit of the forum!

Stay safe :slight_smile:

Hi @velmurugan,

Issue isn’t yet resolved.

Here is the code for information.

            var url = https://${FS_domain}/api/v2/tickets/${ticketId};
            var headers = {
            “Authorization”: Basic <%= encode(iparam.api) %>,
            “Content-Type”: “application/json”
             };
             var body = {
             “description”:“i am anjali”,
              “type”:“Incident”,
              “custom_fields”:{
                    “user_id”:UserValue
               }
              };
               var options = {
                  headers: headers,
                  body: JSON.stringify(body)
               };
                 $request.put(url, options).then(function (data) {
               console.log(data);
                 }, function (error) {
               console.log(error);
                });

Thanks,
Tipuranjali.

Hi, @Tipuranjali!

As far as I know, it is not possible to update a service request ticket.
I raised a ticket several months ago about it, the status is still waiting on feature request.

4 Likes