# Freshservice

## Create a Ticket in Freshservice via Webhook Template

Follow the below steps to configure the “Freshservice - Create Ticket” action via webhooks.

1. Login to your **Freshservice Portal** -> your **Profile** (top right) -> **Profile Settings** -> **View API Key**

<div><figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-f41c84df0b67e01242c666cdac50b8dd8d72247b%2FScreenshot%202023-06-06%20at%2018.18.23.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-953729e53f34597a8de62966b63e5173905515e0%2FScreenshot%202023-06-06%20at%2018.18.42.png?alt=media" alt=""><figcaption></figcaption></figure></div>

2. Copy the **API Key** from Freshservice to Create Tickets

## Generate Basic Token using the API Key

You need to generate a basic token using their API Key to authenticate Freshservice APIs. Use a tool to generate a basic token out of the API Key.

Here we have used [<mark style="color:blue;">Postman</mark>](https://www.postman.com/) to generate the basic token

1. Open a new tab in **Postman**
2. Paste the below curl in the **URL** space

<div><figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-9566ac18364955b77baed6ff426a1ec1fe3dc6bf%2FScreenshot%202023-04-28%20at%2018.10.25.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-36d3fe65fb5136abd969e89c438de4a37ac89ebc%2FScreenshot%202023-04-28%20at%2018.10.39.png?alt=media" alt=""><figcaption></figcaption></figure></div>

3. Navigate to **Authorization** -> Type **Basic Auth** -> In the **Username** field paste the **API Key** copied from the profile page.
4. Navigate to **Headers** -> Key **Authorization** -> Copy the **Value**

> curl -v -u apikey:X -H "Content-Type: application/json" -X GET <mark style="color:blue;">'</mark>[<mark style="color:blue;">https://domain.freshservice.com/api/v2/tickets</mark>](https://domain.freshservice.com/api/v2/tickets)<mark style="color:blue;">'</mark>

{% hint style="info" %}
**Note:**

Replace the word “**domain**” in the URL with your **Domain Name**
{% endhint %}

## Using Webhooks to create Freshservice tickets for Squadcast Incidents

1. Navigate to **Settings** -> **Webhooks**.
2. Click **Add Webhook**. On the next screen, you will be guided through three steps. Navigate between these steps by clicking on any of the steps on the top bar.
3. **Add Webhook Details**:

   1. **Webhook Name**: Enter the webhook name as **Freshservice - Create Ticket**.
   2. **Webhook Description** (optional): Enter an optional description. For example - This webhook is for ticket creation in Freshservice for Squadcast Incidents.
   3. **Failure Notification Email** (optional): Enter an email where you want to receive failure notifications. This is particularly helpful when you (or an administrator) want to be notified of webhook-related failures.
   4. **URL**: Copy and paste the below API.
   5. **Additional Headers**: Add `Key: Authorization` and paste the `Value` copied from Postman with the prefix **Basic**

   [<mark style="color:blue;">https://domain.freshservice.com/api/v2/tickets</mark>](https://domain.freshservice.com/api/v2/tickets)

{% hint style="info" %}
**Note:**

Replace the word “**domain**” in the URL with your **Domain Name** and make sure you have selected the **POST** request.

Under Additional headers, Content-Type: application/JSON is added by default.
{% endhint %}

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-bf1d9cc1c932f62b1065243c38afb3a8767e6063%2FScreenshot%202023-06-06%20at%2018.24.42.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Click **Next: Choose Webhook Type**, and navigate to the next step.

4. **Choose Webhook Type**: Choose Webhook type (Manual or Automatic) and add configurations.
   1. **Manual Webhook**: Manually trigger Webhooks under incidents, on demand. Under Manual Webhook, select the teams that are authorized to access the Webhook. You can select All Teams or enter specific Teams, from the drop-down.

{% hint style="info" %}
**Note:**

Select this option only if you want to create Freshservice tickets manually on-demand. If you want a ticket, created automatically when certain conditions are met, please choose Automatic webhooks.
{% endhint %}

2. **Automatic Webhook**: Automatically trigger Webhooks when the configured conditions match. To set up Automatic Webhook Configurations:
   1. **Versions**: Select **v2**
   2. **Triggers**: Select the following Trigger events (conditions) for which the Webhook will be triggered:
      1. Incident Triggered (This will create a Freshservice ticket whenever a new incident gets triggered in Squadcast)
   3. **Filters**: You can apply filters on top of events, based on Teams, Services, Alert Sources, and Tags, by having an individual expression or a combination of expressions/expression groups.

Applying filters will trigger the webhook and create Freshservice tickets only for events that match the filter.

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-ab8c1674f1f5ed459fbe4a3038b76343d435b450%2FScreenshot%202023-04-28%20at%2018.14.39.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Click **Next: Configure Payload**, and navigate to the next step.

5. **Configure Payload**:\
   \
   Select the pre-configured template for **Freshservice - Create Ticket**. You can also test the Webhook by clicking the **Test Webhook** on the bottom right.

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fgit-blob-973f97f0d7becbb7517fcb5a827e5fc73c842d7e%2FScreenshot%202023-06-06%20at%2020.00.47.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

{% hint style="info" %}
**Note:**

We have added the necessary fields in the template. You can change the **Priority** and **Status** according to your use case and add additional ticket fields.

Email/PhoneNumber/UserID is necessary to create a ticket in Freshservice using API. We have added a dummy phone number, you can add relevant fields according to your wish.

You can also [use this link](https://api.freshservice.com/#create_ticket) to check the fields accepted by Freshservice API.
{% endhint %}

Click **Save** and your **Webhook** is created.

*Have any questions?* [*Ask the community*](https://community.squadcast.com/view/home)*.*
