# API Playground

## 개요

Panther Console의 API Playground에서 GraphQL API와 REST API의 작업을 시험해 볼 수 있습니다.

### Playground에 액세스하는 방법

{% hint style="info" %}
Playground에 액세스하려면 `API 토큰 보기` 권한이 있어야 합니다—방법은 다음을 참조하세요. [Panther의 역할 기반 액세스 제어](https://docs.panther.com/ko/system-configuration/rbac) 사용자 역할 수정 방법은 문서를 참조하세요.
{% endhint %}

1. Panther Console의 오른쪽 상단 모서리에서 톱니바퀴 아이콘을 클릭합니다.
2. 드롭다운 메뉴에서 다음을 클릭하세요. **API Playground**.
3. 창 상단의 탭을 사용하여 테스트할 API 세트를 선택합니다: [GraphQL](https://docs.panther.com/ko/panther/api/graphql) 또는 [REST](https://docs.panther.com/ko/panther/api/rest).
   * 다음에 API Playground를 방문하면 마지막으로 사용하던 API로 이동합니다.\\

     <figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-921909836eb4e4dbe9fa6246a3e5f5810735b33d%2FScreenshot%202024-03-13%20at%209.36.22%20AM.png?alt=media" alt="Two tabs are shown: GraphQL and REST." width="204"><figcaption></figcaption></figure>

{% hint style="warning" %}
참고:

* API 토큰을 방금 생성한 경우, 새 토큰이 관련 분산 AWS 서비스에서 사용 가능해질 때까지 30\~60초 정도 기다려 주세요.
* 보안상의 이유로 API 토큰은 **표시되지 않지만** 페이지를 새로고침하거나 다른 페이지로 이동해도 Playground에 유지됩니다. Playground를 사용할 때마다 API 토큰을 다시 입력해야 합니다.
  {% endhint %}

## GraphQL Playground

유효한 API 토큰을 입력한 후, 왼쪽 상단의 "재생" 아이콘을 클릭하여 GraphQL 쿼리가 실행되도록 합니다.

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-5b66d79e91950a0f794860c80641e340eeba2579%2Fapi-playground.png?alt=media" 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>

### 문서 탐색기

Panther Console의 문서 탐색기는 Panther API 스키마를 살펴보는 한 가지 방법입니다. 다운로드 가능한 스키마 파일을 포함한 다른 방법을 알아보려면 다음을 참조하세요. [Panther GraphQL 스키마 살펴보기](https://docs.panther.com/ko/panther/graphql#discover-the-panther-graphql-schema).

다음을 참조하세요. **문서 탐색기** Playground의 오른쪽에 있습니다. 사용 가능한 쿼리와 변이, 그리고 모든 필드와 엔터티의 설명과 유형을 표시합니다:

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-ffcc6839eff8784e1ba9fab0906c3e7da88dc9b3%2Fdocumentation-explorer.png?alt=media" 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>

### 직접 쿼리 작성하기

자동 완성 기능과 문서 탐색기는 직접 쿼리를 작성하는 데 도움이 됩니다. 또한 페이지 상단 근처에는 세 개의 유틸리티 버튼이 있습니다:

* **예쁘게 정리** GraphQL 표준에 맞게 쿼리 형식을 지정하는 데 도움을 줍니다
* **복사** 요청을 보낼 클라이언트에 붙여넣기 위해 쿼리를 복사합니다
* **curl 복사** curl 명령줄 도구가 설치된 모든 UNIX 시스템에 붙여넣을 수 있는 완전한 curl 작업을 복사합니다.

Panther 웹 애플리케이션에서 복사되는 curl 명령의 예:

```
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 # 조직의 사용자를 나열하는 예제 쿼리\n query Users {\n users {\n\t\t\tgivenName\n familyName\n email\n }\n }","variables":{}}' \
--compressed
```

## REST Playground

REST Playground를 사용하여 Panther를 살펴보고 시험해 보세요 [REST API](https://docs.panther.com/ko/panther/api/rest).

### API 토큰 설정 방법

1. 오른쪽 상단에서 다음을 클릭하세요. **권한 부여**.\\

   <figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-d45e4184dbc086ecc14ec50b5c02792313ca434e%2Fimage.png?alt=media" alt="An arrow is drawn to a button labeled &#x22;Authorize.&#x22;"><figcaption></figcaption></figure>
2. 모달에서 API 키를 입력합니다.
3. 다음을 클릭하세요. **권한 부여**의 가장 높은 패치 버전으로 업그레이드한 다음, **닫기**.

### API 그룹 탐색

API 그룹은 먼저 API별 URL 경로에 따라 모아져 나열됩니다. 요청 인수와 예시 반환 페이로드를 포함하여 특정 엔드포인트의 추가 세부 정보를 보려면 엔드포인트 행 오른쪽의 화살표를 클릭합니다.

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-fc44dfe4ec3405a186dbb848d3ea451e49b30d7a%2FScreenshot%202024-03-13%20at%2012.18.06%20PM.png?alt=media" 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>

#### 요청 보내기

{% hint style="info" %}
성공적으로 요청하려면 Playground에 API 토큰을 이미 추가해야 합니다. 위의 [API 토큰 설정 방법](#how-to-set-your-api-token)를 참조하세요.
{% endhint %}

Playground에서 요청을 보내려면:

1. 확장된 API 엔드포인트 내에서 **시도해 보기**.
2. 다음에서 **Parameters** 섹션을 클릭한 다음, 필요한 경우 필요한 및 선택적 매개변수에 값을 입력합니다.
3. 다음을 클릭하세요. **실행**.

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-e63dc4fd84074ce8fd04309b439816daf9f69bb7%2FScreenshot%202024-03-13%20at%2012.29.55%20PM.png?alt=media" 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>

### 스키마 보기

API 그룹 아래에는 각 데이터 유형의 스키마가 나열됩니다:

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-e8a6915f20c839b432352f6329595b8582085fbe%2FScreenshot%202024-03-13%20at%2011.52.03%20AM.png?alt=media" alt="The Schema section showing all the data types grouped by name"><figcaption></figcaption></figure>

특정 데이터 유형의 세부 정보를 보려면 해당 행을 클릭하여 확장합니다:

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-84ddaf7b19a1c3791e489fbd4d870ea7145e26f9%2FScreenshot%202024-03-13%20at%2012.43.27%20PM.png?alt=media" alt="A &#x22;RuleAPI.Rule&#x22; entity is shown. Part of the JSON body is expanded, while other parts are closed."><figcaption></figcaption></figure>

이러한 스키마는 다음을 할 때도 볼 수 있습니다 [API 그룹 보기](#exploring-api-groups)의 **응답** 섹션에서 **예시 값**의 오른쪽에서, 다음을 클릭합니다 **스키마**.

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-b136333ae79d6db83f3394f81757e4a662e4f719%2Fdatamodelschema.png?alt=media" alt="Inline schema block in the Responses portion of an API Group, showing the datatype where it is used."><figcaption></figcaption></figure>
