Question - API Logic when trying to update a ticket

Hello,

I have question regarding the Fresh Desk API when using webhooks during automation flows.

I have built a basic test flow as below;

When Ticket is updated > Containing Subject XYZ & Also Containing Category XYZ > Trigger Webhook

The Webhook completes a PUT request to update a custom field on the ticket and change the status to 5 (closed).

If my callback URL is for example - https://domain.freshservice.com/api/v2/tickets/25

When testing this webhook with the built in test method this works fine see below;

However when I change the callback URL to include a place holder for the ticket number like so - https://domain.freshservice.com/api/v2/tickets/{{ticket.id}}

I get 405 method not allowed like so;

Which translates to this error;

I just made a PUT request when using the direct ticket number of 25? but it doesn’t allow it when I used the placeholder to set the ticket number dynamically?

Also reading this article here Using webhooks in automation rules that run on ticket updates : Freshdesk Support suggests the PUT request can be made to /api/v2/tickets

I figured this may have been an issue with the built in tester, however I have also tested this by testing the actual flow.

I get the same result if I set the URL to state /25 it works, if I set the URL to {{ticket.id}} it doesn’t so I’m a little confused.

Thanks

2 Likes

Hello @John8908, the reason its failing is because {{ticket.id}} for freshservice is a string that is formatted like so: “INC-25”. This doesn’t work since the URL is looking for a numeric ID. So you just need to use the placeholder {{ticket.id_numeric}} and your webhook will work.

When working with placeholders, it is always a good idea to print the placeholder out to as a note to the ticket to see it’s true value. Hope that helps!

Take care!

Hi @Zach

Many thanks, your explanation makes sense now! I have tested the workflow with the amended change. When I go into the ticket and update it, the webhook does indeed now work when triggered by the condition.

The test webhook feature still showed the error, so i’m guessing this may be a limitation on the test webhook feature inside the webhook interface?

Thanks for your help!

Hi @Zach

One last question if you don’t mind.

When using the API/Webhook to do a PUT request on a ticket to update a custom field which uses a data source of all users for example

Whats the best value to populate that with, below is the JSON without the value.

{
    "custom_fields": {
        "user_notified": 
    }
}

Would it be Agent or Requestor ID taken from the end of the URL of the specific agent or requestor for example;

*https://domain.freshservice.com/agents/1111111

*https://domain.freshservice.com/itil/requesters/2222222

Then based off that specific value I could use a placeholder like

{
    "custom_fields": {
        "user_notified": {{ticket.requester.id}}
    }
}

Or would it be easier using an email address?

{
    "custom_fields": {
        "user_notified": "email@mail.net"
    }
}

Thanks

Hello @John8908, in my experience, email address has been easier to use. Which you should still be able to access from the “requester” placeholders.

Hope that helps

Hi @Zach

That make sense thank you, sadly upon trying this I was met with an error when testing the webhook with the below JSON

{
    "status": 3,
    "custom_fields": {
        "user_notified": "{{ticket.from_email}}"
    }
}

Since I have seen this error previously and the webhook triggered as part of the workflow regardless of failing in this testing stage area with the above error.

I checked the ticket activities and seen it had failed as per below screenshot;

I don’t seem to have an issue updating things like group, department etc on the ticket using the relevant group or department ID’s if I amend the webhook to do so as part of the below flow.

However updating a contact field which looks up against all users is proving tricky.

Back to the drawing board I guess!

Thanks

@Zach

Just to update on this I tried this via a terminal using curl with the verbose switch included.

It stated;

Unexpected/invalid field in request

Reading the API documentation - Freshdesk

The translates to the below;

So I guess you cant use the API to trigger a webhook to make a PUT request to a custom field using a data source of all users?

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.