<!-- llms.txt: https://workos.com/llms.txt -->
<!-- feedback.md: https://workos.com/docs/feedback.md -->

# Widgets API

The Widgets API is the GraphQL API that powers WorkOS Widgets. Requests to it are authenticated with short-lived, session-bound Widgets API tokens.

## Generate a Widgets API token

Generate a short-lived, session-bound token for the Widgets API, scoped to an organization and user.

:::code-group

```bash language="curl" title="Request" tab="1"
curl --request POST \
  --url "https://api.workos.com/client/token" \
  --header "Authorization: Bearer sk_example_123456789" \
  --header "Content-Type: application/json" \
  -d @- <<'BODY'
    {
        "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT",
        "user_id": "user_01E4ZCR3C56J083X43JQXF3JK5"
    }
BODY
```

```rb language="ruby" title="Request" tab="1"
require "workos"

WorkOS.configure do |config|
  config.api_key = "sk_example_123456789"
end

WorkOS.client.client_api.create_token(
  organization_id: "org_01EHZNVPK3SFK441A1RGBFSHRT",
  user_id: "user_01E4ZCR3C56J083X43JQXF3JK5"
)
```

```py language="python" title="Request" tab="1"
from workos import WorkOSClient

client = WorkOSClient(api_key="sk_example_123456789", client_id="client_123456789")

client.client_api.create_token(
    organization_id="org_01EHZNVPK3SFK441A1RGBFSHRT",
    user_id="user_01E4ZCR3C56J083X43JQXF3JK5",
)
```

```go language="go" title="Request" tab="1"
package main

import (
	"context"

	"github.com/workos/workos-go/v10"
)

func main() {
	client := workos.NewClient("sk_example_123456789")

	_, err := client.ClientAPI().CreateToken(context.Background(), &workos.ClientAPICreateTokenParams{
		OrganizationID: "org_01EHZNVPK3SFK441A1RGBFSHRT",
		UserID:         "user_01E4ZCR3C56J083X43JQXF3JK5",
	})
	if err != nil {
		panic(err)
	}
}
```

```php language="php" title="Request" tab="1"
<?php

use WorkOS\WorkOS;

$workos = new WorkOS(
    apiKey: "sk_example_123456789",
    clientId: "client_123456789",
);

$workos
    ->clientApi()
    ->createToken(
        organizationId: "org_01EHZNVPK3SFK441A1RGBFSHRT",
        userId: "user_01E4ZCR3C56J083X43JQXF3JK5",
    );
```

```java language="java" title="Request" tab="1"
import com.workos.WorkOS;
import com.workos.clientapi.ClientApiApi.CreateTokenOptions;

WorkOS workos = new WorkOS("sk_example_123456789");

CreateTokenOptions options = CreateTokenOptions.builder()
                                 .organizationId("org_01EHZNVPK3SFK441A1RGBFSHRT")
                                 .userId("user_01E4ZCR3C56J083X43JQXF3JK5")
                                 .build();

workos.clientApi.createToken(options);
```

```cs language="dotnet" title="Request" tab="1"
using WorkOS;

var client = new WorkOSClient(new WorkOSOptions {
    ApiKey = "sk_example_123456789",
    ClientId = "client_123456789",
});

await client.ClientApi.CreateTokenAsync(new ClientApiCreateTokenOptions {
    OrganizationId = "org_01EHZNVPK3SFK441A1RGBFSHRT",
    UserId = "user_01E4ZCR3C56J083X43JQXF3JK5",
});
```

```rust language="rust" title="Request" tab="1"
use workos::Client;
use workos::client_api::CreateTokenParams;

#[tokio::main]
async fn main() -> Result<(), workos::Error> {
    let client = Client::builder()
        .api_key("sk_example_123456789")
        .client_id("client_123456789")
        .build();

    let _result = client
        .client_api()
        .create_token(
            CreateTokenParams {
                organization_id: "org_01EHZNVPK3SFK441A1RGBFSHRT".into(),
                user_id: "user_01E4ZCR3C56J083X43JQXF3JK5".into(),
                ..Default::default()
            }
        )
        .await?;

    Ok(())
}
```

```json language="json" title="Response" tab="2"
{
  "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InNlc3Npb24..."
}
```

:::

### POST /client/token

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `organization_id` | string | Yes | The ID of the organization to scope the Widgets API token to. |
| `user_id` | string | Yes | The ID of the user to issue the Widgets API token for. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `token` | string | The Widgets API token. |