# API Playground

## Overview

Within the API Playground in the Panther Console, you can try out operations in the GraphQL API and REST API.

### How to access the Playground

{% hint style="info" %}
You must have the `View API Tokens` permission to access the Playground—see [Panther's Role-Based Access Control](../../system-configuration/rbac) documentation for instructions on modifying user roles.
{% endhint %}

1. In the upper-right corner of your Panther Console, click the gear icon.&#x20;
2. In the dropdown menu, click **API Playground**.
3. Using the tabs at the top of the window, select the API set you'd like to test: [GraphQL](graphql) or [REST](rest).
   *   The next time you visit the API Playground, you will be taken to whichever API you left off on.\


       <figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2F47D2i1fWPsmlKVNwqKaY%2FScreenshot%202024-03-13%20at%209.36.22%20AM.png?alt=media&#x26;token=8ae4c85b-7f8b-4d77-a5ab-c82bf7bc7bde" alt="Two tabs are shown: GraphQL and REST." width="204"><figcaption></figcaption></figure>

{% hint style="warning" %}
Note:

* If you have just created an API token, please wait 30-60 seconds for the new token to become available to related distributed AWS services.
* For security purposes, the API token will **not** persist in the Playground when you refresh the page or navigate to a different page. You will need to re-enter the API token each time you use the Playground.
{% endhint %}

## GraphQL Playground

After you enter a valid API Token, click the "play" icon in the upper left corner to force your GraphQL query to run.

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2F4dQcIe1p3a7dFSZOALDv%2Fapi-playground.png?alt=media&#x26;token=9b8577bb-aa25-4536-b5bc-b15742e3fff9" alt="The API Playground&#x27;s default view shows an example query in a code editor on the left. On the right, there is a column labeled Documentation Explorer."><figcaption></figcaption></figure>

### Documentation Explorer

The Documentation Explorer in the Panther Console is one way to examine the Panther API schema. To learn about other ways, including a downloadable schema file, see [Discover the Panther GraphQL schema](../graphql#discover-the-panther-graphql-schema).

See the **Documentation Explorer** on the right side of the Playground. It displays the available queries and mutations, along with descriptions and types on every field and entity:

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FXBOcpuimM2K8O7OTvvZR%2Fdocumentation-explorer.png?alt=media&#x26;token=ef10c710-a8c8-4dd8-b5f2-4165f8c6430d" alt="The image shows the Documentation Explorer that appears on the right side of the API Playground. It has a search field at the top, and a header labeled &#x22;Root Types.&#x22; Under &#x22;Root Types,&#x22; it lists &#x22;query: Query&#x22; and &#x22;mutation: Mutation&#x22;." width="375"><figcaption></figcaption></figure>

### Writing your own query

The autocomplete functionality and the Documentation Explorer assist with writing your own query. Additionally, there are three utility buttons near the top of the page:&#x20;

* **Prettify** to help you format your query according to the GraphQL standards
* **Copy** to copy your query in order to paste it to the client that's going to issue the request
* **Copy curl** to copy a complete curl operation that you can paste into any UNIX system with the curl command-line tool installed.

An example of the curl command that would be copied from the Panther web application:

```
curl 'PANTHER_GRAPHQL_API_URL' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Connection: keep-alive' \
-H 'DNT: 1' \
-H 'Origin: http://{PANTHER_GRAPHQL_API_URL}/public/graphql' \
-H 'X-API-Key: {FAKE_API_KEY_WITH_USER_READ_PERMISSIONS}' \
--data-binary '{"query":"\n # Example query which lists users in your organization\n query Users {\n users {\n\t\t\tgivenName\n familyName\n email\n }\n }","variables":{}}' \
--compressed
```

## REST Playground

{% hint style="info" %}
The REST Playground is in open beta starting with Panther version 1.103, and is available to all customers. Please share any bug reports and feature requests with your Panther support team.
{% endhint %}

Use the REST Playground to explore and try out the Panther [REST API](rest).

### How to set your API token

1.  In the upper-right corner, click **Authorize**.\


    <figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FCYNNxajfhWuL3Qu7gvhp%2Fimage.png?alt=media&#x26;token=c06f755d-c195-499d-b3e5-d0757c3d838b" alt="An arrow is drawn to a button labeled &#x22;Authorize.&#x22;"><figcaption></figcaption></figure>
2. In the modal, enter your API key.
3. Click **Authorize**, then **Close**.

### Exploring API groups

The API groups are listed first, collected together by URL path for each API. To view additional details for a certain endpoint, including request arguments and an example return payload, click the arrow on the right-hand side of an endpoint's row.

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FJorkOfLrPWNTlimyqyRz%2FScreenshot%202024-03-13%20at%2012.18.06%20PM.png?alt=media&#x26;token=51cdf4a4-7c45-4465-bbf9-e10845733b7b" alt="Under a header reading &#x22;Panther REST API,&#x22; a grouping of data model endpoints is shown. There are GET (list), POST, DELETE, GET, and PUT endpoints. "><figcaption></figcaption></figure>

#### Sending requests

{% hint style="info" %}
To make a successful request, you must have already added your API token in the Playground. See [How to set your API token](#how-to-set-your-api-token), above.
{% endhint %}

To send a request in the Playground:

1. Within an expanded API endpoint, click **Try it out**.
2. In the **Parameters** section, provide values for required and optional parameters, as you see fit.
3. Click **Execute**.

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FMDAHUnNBHTF66ajXBPst%2FScreenshot%202024-03-13%20at%2012.29.55%20PM.png?alt=media&#x26;token=e611cbe7-2876-4fc1-8681-b72646682086" alt="Within a GET /rules section, a &#x22;Try it out&#x22; button is circled. Two parameters are shown: cursor, and limit."><figcaption></figcaption></figure>

### Viewing schemas

Below the API groups, the schemas for each data type are listed:

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FwuWavHo2HwcmrXPZ2M9W%2FScreenshot%202024-03-13%20at%2011.52.03%20AM.png?alt=media&#x26;token=5f845148-0bd7-4bc1-b0c0-801f0442f899" alt="The Schema section showing all the data types grouped by name"><figcaption></figcaption></figure>

To view details of a certain data type, click its row to expand it:

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fp5bHaZxiXS1WkrWiVEjW%2FScreenshot%202024-03-13%20at%2012.43.27%20PM.png?alt=media&#x26;token=a54c7ffe-6f9d-410e-8839-3388a406d079" alt="A &#x22;RuleAPI.Rule&#x22; entity is shown. Part of the JSON body is expanded, while other parts are closed."><figcaption></figcaption></figure>

These schemas are also visible when [viewing the API groups](#exploring-api-groups). In the **Responses** section, next to **Example Value**, click **Schema**.

<figure><img src="https://4011785613-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2FLvVvX1cULcB9BlE3AyWJ%2Fdatamodelschema.png?alt=media&#x26;token=6445a07d-e216-425a-a507-beab2b4fe20c" alt="Inline schema block in the Responses portion of an API Group, showing the datatype where it is used."><figcaption></figcaption></figure>
