# Create an API Key

## Introduction

The ServiceNow Table API allows programmatic interaction with incidents, providing functionalities for creating, searching, updating, and deleting incidents.

To securely use this API, various authentication methods are available. In this guide, we will focus on using the API key for authentication.

In this guide, we will learn to:

- Generate and configure an API key, enabling interaction with ServiceNow tables and records.
- Set up a Business Rule to automatically send a request to a webhook whenever a record is created.

## Prerequisites

Before getting started, make sure you have:

- A ServiceNow administrator account
- The URL of your ServiceNow instance

Follow these steps:

1. Create a **REST API Key** to serve as the authentication credential.

2. Set up an **Authentication Profile** to define how the API key should be included in requests.

3. Configure an **API Access Policy** to specify the permissions associated with the API key.

## Walkthrough

1. **Create a REST API key**

   In **`All > System Web Service > REST API Key`**, you can create an API key (_see screenshot_).
   - You can set an expiration date for the key.

   <div class="docs-screenshot-compact">

   ![You can set expiration date key](./assets/you-can-set-expiration-date-key.png)

   </div>

1. **Set up an Authentication Profile**

   In **`All > System Web Service > API Access Policies > Inbound Authentication Profile`**, you can define the required parameters for authenticating each incoming request.

   <div class="docs-screenshot-compact">

   ![Set up authentication profile](./assets/set-up-authentication-profile.png)

   </div>

   In **“Select Target Record”**, we recommend choosing the **`x-sn-apikey`** parameter as an **Auth Header** type.

   <div class="docs-screenshot-compact">

   ![Set up authentication profile](./assets/set-up-authentication-profile-3.png)

   </div>

   <div class="docs-screenshot-compact">

   ![Set up authentication profile](./assets/set-up-authentication-profile-2.png)

   </div>

   then `submit` .

1. **Configure an API Access Policy**

   In **`All > System Web Service > API Access Policies > REST API Access Policies`**, you can define access policies for API tokens, specifying which API, methods, and endpoints they can interact with.
   - In **REST API**, select **Table API** as the target API.
   - Manage permissions by configuring access at the **method, path, or version** level.
   - By unchecking the default option that grants full access, you can define a more restrictive and tailored access policy for your API tokens.

   <div class="docs-screenshot-compact">

   ![Unchecking default option grants full access](./assets/unchecking-default-option-grants-full-access.png)

   </div>

   <div class="docs-screenshot-compact">

   ![Unchecking default option grants full access](./assets/unchecking-default-option-grants-full-access-2.png)

   </div>

   <div class="docs-screenshot-compact">

   ![Unchecking default option grants full access](./assets/unchecking-default-option-grants-full-access-3.png)

   </div>

select the Authentication profile created

   <div class="docs-screenshot-compact">

   ![Unchecking default option grants full access](./assets/unchecking-default-option-grants-full-access-4.png)

   </div>

In Mindflow, you can now create a credential in the appropriate environment to interact with ServiceNow tables and records. When creating a credential, you must select **HTTP API KEY** as the credential type. In the **Header**, add an item where the key is `x-sn-apikey` and the hidden value is the `token`.

   <div class="docs-screenshot-compact">

   ![Unchecking default option grants full access](./assets/unchecking-default-option-grants-full-access-5.png)

   </div>
