# ServiceNow

## Generate Basic Token using the API Key

You need to generate a basic token using their API Key to authenticate Freshdesk 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%2FvtDiisYwfuKnrOnzAFbY%2FScreenshot%202023-05-10%20at%2020.17.38.png?alt=media&#x26;token=da60d47a-fa12-44c9-87e4-c23c256efff3" alt=""><figcaption></figcaption></figure> <figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FWpmoJaIHsOEhUf7Zq39P%2FScreenshot%202023-05-10%20at%2020.17.47.png?alt=media&#x26;token=a19115c8-d6c7-461b-b0b8-e7e410abf79a" 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://instance.service-now.com/api/now/table/incident</mark>](https://dev124394.service-now.com/api/now/table/incident)<mark style="color:blue;">'</mark>

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

Replace the word “**instance**” in the URL with your **Instance Name**
{% endhint %}

## Create a Ticket in ServiceNow via Webhook Template

Follow the below steps to configure the “ServiceNow - Create Ticket” action via Webhooks:

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**:&#x20;
   1. **Webhook Name**: Enter the webhook name as **ServiceNow - Create Ticket**.
   2. **Webhook Description** (optional): Enter an optional description. For example - This webhook is for ticket creation in ServiceNow 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**: Enter the **Webhook URL** copied from **ServiceNow**.&#x20;
   5. **Additional Headers**: Add `Key: Authorization` and paste the `Value` copied from Postman

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2F0S2R8xXDT1KyuhExbRcZ%2FScreenshot%202023-05-10%20at%2020.12.31.png?alt=media&#x26;token=ca401043-f6a4-46d5-9daa-f83de8781ad3" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**To copy Webhook URL from ServiceNow:**&#x20;

1\) Log in to your ServiceNow Instance (dev\*\*\*\*\*133.service-now\.com)

2\) Search for the Rest API Explorer and open it

3\) In the Rest API Explorer page choose the Namespace and API Name with the proper API version.
{% endhint %}

{% hint style="info" %}
**Note:**&#x20;

Make sure you have selected the POST request.

Content-Type: application/JSON is added by default under Headers
{% endhint %}

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 ServiceNow tickets manually on-demand. If you want a ticket, created automatically when certain conditions are met, please choose Automatic webhooks.
{% endhint %}

**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 ServiceNow ticket whenever a new incident gets triggered in Squadcast)&#x20;
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 ServiceNow tickets only for events that match the filter. Check the example config below:

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FuGM3IZxqGS9eWj9EflB9%2FScreenshot%202023-05-08%20at%2011.28.13.png?alt=media&#x26;token=534c8cd6-b135-4699-89f2-4b87bab361b4" alt=""><figcaption></figcaption></figure>

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

5. **Configure Payload**:\
   \
   Select the pre-configured template for **ServiceNow - 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%2FF2nt09GjRpqDexgLzM5P%2FScreenshot%202023-04-26%20at%2016.34.37.png?alt=media&#x26;token=dee524a9-5b82-4133-ad76-79c590bd4eb8" alt=""><figcaption></figcaption></figure>

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

We have added the necessary fields in the template. You can change the **Keys** that are mandatory according to your use case and can add additional ticket fields.
{% endhint %}

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