
## Assign API token as connection admin

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/packages/how-tos/manage-api-token-connections

> Assign an API token as a connection admin in Atlan using APITokenConnectionAdmin and the Python SDK (pyatlan).

# APITokenConnectionAdmin: manage API token connections

Use `APITokenConnectionAdmin` in the Atlan Python SDK to programmatically assign an API token as a connection admin.

The [API token connection admin package](https://docs.atlan.com/llms/platform/get-started/api-token-connection-admin/llms.txt)
allows you to assign an API token to a connection as a connection admin. This is a necessary step when:

- A connection is created through a workflow, run by a user
- You want to use an API token to programmatically administrate
the connection or its assets (in particular, to manage policies in a persona)

## Configuration

To set up the API token connection admin with the specified configuration.

### Java

:::warning[Coming soon]
:::

### Python

```python showLineNumbers title="API token connection admin with the specified configuration"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.packages import APITokenConnectionAdmin

client = AtlanClient()

workflow = (
 APITokenConnectionAdmin() # (1)
 .config( # (2)
 connection_qualified_name="default/snowflake/1234567890",
 api_token_guid="92588c67-5ddf-4a45-8b5c-dd92f4b84e99",
 )
 .to_workflow() # (3)
)

response = client.workflow.run(workflow) # (4)
```

1. The API token connection admin package allows you
to assign an API token to a connection as a connection admin.
2. Set up the API token connection admin with the specified configuration.

 - connection_qualified_name: connection qualified name
 to which you want to add the API token as a connection admin
 - api_token_guid: GUID of the API token

3. Convert the package into a `Workflow` object.
4. Run the workflow by invoking the `run()` method
on the workflow client, passing the created object.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously.
See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt)
for details on how to check the status and wait
until the workflow has been completed.
 :::

### Kotlin

:::warning[Coming soon]
:::

### Raw REST API

:::tip[Create the workflow via UI only]
We recommend creating the workflow only via the UI.
To rerun an existing workflow, see the steps below.
:::

## Re-run existing workflow

To re-run an existing api token connection admin workflow:

### Java

:::warning[Coming soon]
:::

### Python

```python showLineNumbers title="Re-run existing api token connection admin workflow"
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.enums import WorkflowPackage

client = AtlanClient()

existing = client.workflow.find_by_type( # (1)
 prefix=WorkflowPackage.API_TOKEN_CONNECTION_ADMIN, max_results=5
)

# Determine which api token connection admin workflow (n)

# from the list of results you want to re-run.

response = client.workflow.rerun(existing[n]) # (2)
```

1. You can find workflows by their type using the workflow client `find_by_type()`
method and providing the **prefix** for one of the packages.
In this example, we do so for the `APITokenConnectionAdmin`. (You can also specify
the **maximum number of resulting workflows** you want to retrieve as results.)
2. Once you've found the workflow you want to re-run,
you can simply call the workflow client `rerun()` method.

 - Optionally, you can use `rerun(idempotent=True)` to avoid re-running a workflow that's already in running or in a pending state.
 This will return details of the already running workflow if found, and by default, it's set to `False`.

 :::warning[Workflows run asynchronously]
Remember that workflows run asynchronously. See the [packages and workflows introduction](https://docs.atlan.com/llms/platform/python/packages/llms.txt)
for details on how you can check the status and wait until the workflow has been completed.
 :::

### Kotlin

:::warning[Coming soon]
:::

### Raw REST API

:::warning[Requires multiple steps through the raw REST API]
1. Find the existing workflow.
2. Send through the resulting re-run request.
:::
```json showLineNumbers title="POST /api/service/workflows/indexsearch"
{
 "from": 0,
 "size": 5,
 "query": {
 "bool": {
 "filter": [
 {
 "nested": {
 "path": "metadata",
 "query": {
 "prefix": {
 "metadata.name.keyword": {
 "value": "csa-api-token-connection-admin" // (1)
 }
 }
 }
 }
 }
 ]
 }
 },
 "sort": [
 {
 "metadata.creationTimestamp": {
 "nested": {
 "path": "metadata"
 },
 "order": "desc"
 }
 }
 ],
 "track_total_hits": true
}
```

1. Searching by the `csa-api-token-connection-admin` prefix will make sure you only find existing api token connection admin workflows.

 :::tip[Name of the workflow]
The name of the workflow will be nested within the `_source.metadata.name` property of the response object.
(Remember since this is a search, there could be multiple results, so you may want to use the other
details in each result to determine which workflow you really want.)
 :::
```json title="POST /api/service/workflows/submit"
{
 "namespace": "default",
 "resourceKind": "WorkflowTemplate",
 "resourceName": "csa-api-token-connection-admin-1684500411" // (1)
}
```

1. Send the name of the workflow as the `resourceName` to rerun it.

---
