> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage API Clients

> Learn how to create API clients.

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Manage API Clients"
  description="Learn how to create API clients."
  steps={[
{
  name: "Create an API Client",
  text: "To create an API client you need to specify the name and desired permissions. You can either specify each permission separately or specify a role. In this example, you create an API client for managing flags. Give it a Flag editor role. Response:",
},
{
  name: "Get an API Client",
  text: "You can get an API client by passing the name of the client to the following endpoint. Response:",
},
{
  name: "List API Clients",
  text: "You can list all API clients in the organization using the following endpoint. Response:",
},
]}
/>

API Clients are machine users that can interact with the Confidence APIs. Confidence has APIs for managing API clients programmatically.

## Create an API Client

To create an API client you need to specify the name and desired permissions. You can either specify each permission separately or specify a role. In this example, you create an API client for managing flags. Give it a `Flag editor` role.

```bash theme={null}
curl -X POST "https://iam.confidence.dev/v1/apiClients" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "My API Client",
    "description": "Client for setting up flags in GHE repos",
    "permissions": [],
    "roles": [
      "roles/726f6c5f68386b6c46596c4a335350384e6a7377"
    ]
  }'
```

Response:

```json theme={null}
{
  "name": "apiClients/donlangsbyz6iiksdt4c",
  "displayName": "My API Client",
  "description": "Client for setting up flags in GHE repos",
  "clientId": "k9KkmxZfQtG6ZPqk9wyQfe7G5EzZsjza",
  "clientSecret": "4wvbCSdF7wlTdn8HJEqSkcuSqyndjwcHzQ3KEwxRcqvkfLeEG4eFapHQUIrRuDxr",
  "permissions": [],
  "roles": [
    "roles/726f6c5f68386b6c46596c4a335350384e6a7377"
  ],
  "createdBy": "users/xa8cecs2cc9xsz8jvgmc",
  "updatedBy": "users/xa8cecs2cc9xsz8jvgmc",
  "labels": {},
  "createTime": "2023-08-29T09:36:57.163017Z",
  "updateTime": "2023-08-29T09:36:57.163017Z"
}
```

## Get an API Client

You can get an API client by passing the name of the client to the following endpoint.

```bash theme={null}
curl -X GET "https://iam.confidence.dev/v1/apiClients/donlangsbyz6iiksdt4c" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

Response:

```json theme={null}
{
  "name": "apiClients/donlangsbyz6iiksdt4c",
  "displayName": "My API Client",
  "description": "Client for setting up flags in GHE repos",
  "clientId": "k9KkmxZfQtG6ZPqk9wyQfe7G5EzZsjza",
  "clientSecret": "4wvbCSdF7wlTdn8HJEqSkcuSqyndjwcHzQ3KEwxRcqvkfLeEG4eFapHQUIrRuDxr",
  "permissions": [],
  "roles": [
    "roles/726f6c5f68386b6c46596c4a335350384e6a7377"
  ],
  "createdBy": "users/xa8cecs2cc9xsz8jvgmc",
  "updatedBy": "users/xa8cecs2cc9xsz8jvgmc",
  "labels": {},
  "createTime": "2023-08-29T09:36:57.163017Z",
  "updateTime": "2023-08-29T09:36:57.163017Z"
}
```

## List API Clients

You can list all API clients in the organization using the following endpoint.

```bash theme={null}
curl -X GET "https://iam.confidence.dev/v1/apiClients" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```

Response:

```json theme={null}
{
  "apiClients": [
    {
      "name": "apiClients/donlangsbyz6iiksdt4c",
      "displayName": "My API Client",
      "description": "Client for setting up flags in GHE repos",
      "clientId": "k9KkmxZfQtG6ZPqk9wyQfe7G5EzZsjza",
      "clientSecret": "4wvbCSdF7wlTdn8HJEqSkcuSqyndjwcHzQ3KEwxRcqvkfLeEG4eFapHQUIrRuDxr",
      "permissions": [],
      "roles": [
        "roles/726f6c5f68386b6c46596c4a335350384e6a7377"
      ],
      "createdBy": "users/xa8cecs2cc9xsz8jvgmc",
      "updatedBy": "users/xa8cecs2cc9xsz8jvgmc",
      "labels": {},
      "createTime": "2023-08-29T09:36:57.163017Z",
      "updateTime": "2023-08-29T09:36:57.163017Z"
    }
  ],
  "nextPageToken": ""
}
```
