Start a new topic

Using Webhooks within Workflow Automation using API v2 with Freshservice

It took me a good deal of time to work out all the kinks in using Webhooks inside Freshservice workflow automation.  I am surprised they don't have the option to create a ticket/child ticket built into the workflows already, but then again they are missing a lot of conditions/actions that should be available there.  I found some documentation from several places that helped, some from Freshdesk API documentation, some from Freshservice API documentation, and some from some external sites.  The fields required are all different between API's and Freshdesk and Freshservice from what I can tell.  Using v2 of the API on Freshservice I still do not see a way to automatically create a child ticket linked to the original ticket.  I found a field called "parent_id", but this field does not work with v2 API.


To anyone that is not a programmer I suggest getting a program called SoapUI, this is what I used to test and find out what fields work and what do not, as there is not real way to see what errors your webhook may cause within Freshservice.


I have attached some pictures of SoapUI on my computer for reference in setting up your test scenarios.  Please follow the below:


Step 1 - install Soap

Step 2 - File Menu - > New REST Project:

           URI will be your Freshservice URL plus API info, HTTPS is required, ex:

          https://xxx.freshservice.com/api/v2/tickets

Step 3 - A new window will open, leave GET as the method at the top left.  At the bottom left you need to click on Auth and add your credentials or token.  I suggest using the Token as passwords can change more easily.  Token can be found on your profile page within Freshservice.

image


Your Request will look like this in Soap:

image


At the bottom left of the request click on "Auth" and add a Basic auth type and use the token as the user, and simply put an "X" as the password. Click on the Header tab right to the right of Auth (just so it saves the credentials). On the right hand side of the request click on JSON as circled in red in the image.  Click the green "play" button at the top left and if you have the correct URL, token, and other items it will pull the tickets it see in your Freshservice portal.  This is important, as this is the only way I was able to locate the department_id(s) and group_id(s) that are required to create new tickets.  You will need reference points points for example, I had 2 tickets assigned to the department/company and the 2 plus agent groups I setup.  Each has a unique number so you will need to store this info for use later.  Each ticket is separated/grouped between { and } so you should be able to get this info.


Now comes the trickier part, adding a new ticket.


Step 4 - In Soap, on the left hand column...right click Ticket[/api/v2/tickets] and choose New method and select POST, then click OK without adding any other details.

image


Add in the token and password "X" under Auth as we did for the first GET method.  Click Headers to save the Auth info.  With the POST method we need additional info that will be sent to Freshservice so we can create a ticket:


image


You see I have some extra data put into the Media Type area, here you should select application/json then you can copy and paste this data to your end:


{
 "department_id":10000XXXXXX,
 "group_id":10000XXXXXX,
 "category":"IT Support",
 "sub_category":"Software",
 "item_category":"test Soap",
 "description":"test description",
 "subject":"test subject",
 "email":"requester-email@requester-domain",
 "cc_emails": ["CCemail@CCdomain","CCemail2@CCdomain2"],
 "priority":1,
 "status":2,
 "source":2,
 "custom_fields": {
  "client_location":"Other"
 }
}

 

On the left hand side of the request window click on JSON again and click the green "play" button.  You should see the following error on the right hand side of the request:


 {
   "code": "invalid_json",
   "message": "Request body has invalid json format"
}

 

This is because we did not submit the correct department_id or group_id or another value in the media field is incorrect.  Your custom_fields may be different than mine so you may need to remove or change those lines.  Make sure you have valid emails specified, remove cc_emails line if not needed.  Categories should match those that you have in your portal, otherwise remove categories as well.  Depending what fiels are set as required you may have to add or remove them from the media info.  Look in the first GET method request for the format of each field.


If you are missing required fields, it will tell you, for example with this info:


{
 "department_id":10000XXXXXX,
 "description":"test description",
 "subject":"test ticket",
 "email":"danielm@complusdata.com",
 "priority":1,
 "status":2,
 "source":2
}

 

I got the following response:


{
   "description": "Validation failed",
   "errors": [
            {
         "field": "category",
         "message": "It should be one of these values: 'Client Service Issue,IT Support,Data Entry Request,Operations'",
         "code": "invalid_value"
      },
            {
         "field": "client_location",
         "message": "It should be one of these values: 'Other,Other2'",
         "code": "missing_field"
      }
   ]
}

 

You these errors to correct your media request info until you finally get it to create a ticket from Soap.  Once you achieve this we can go back to your workflow in Freshservice and add an automation rule to trigger a webhook and we should have everything we need.


image


Where XXX is your domain on freshservice.


image


Username is the token.


Then in the content field paste the same data we used in the Media field on Soap, IE: 

{
	"department_id":10000XXXXXX,
	"category":"IT Support",
        "sub_category": "Handheld",
        "item_category": "Add/Change Violation",
        "group_id":10000XXXXXX,	
	"description":"Parent ticket - {{ticket.id}} \n {{ticket.url}} \n \n {{ticket.description}}",
	"subject":"Violation Change Request (Parent ticket {{ticket.id}}) - {{ticket.subject}}",
	"email":"{{ticket.from_email}}",
        "cc_emails": ["{{ticket.agent.email}}"],
	"priority":1,
	"status":2,
	"source":2,
	"custom_fields": {
		"client_location":"{{ticket.client_location}}"
	}
}

Use the department_id and group_id relevant to your Freshservice portal.


You can Insert Placeholders here so that a ticket can be created with data is already in the portal.  My Webhook creates basically a copy of a ticket for a certain category and assigns it to another Agent group.  As I mentioned before I do not see a way to currently link this ticket to its "parent", so I just include the previous (ticket.id) and details in this ticket so our agents can go look for the original if needed.  Your use case may differ.  When you click on Insert Placeholders you can find out what information can be passed on to the new ticket.


If you are trying to use Webhooks to perform other actions other than creating Tickets, I still suggest using Soap so you can see any errors reported during your trials.  Refer to their documention and with this you may be able to work out the rest:


https://api.freshservice.com/v2/#introduction

Login or Signup to post a comment
JS Bin