Skip to main content
POST
/
organizations
/
{organization}
/
oauth-applications
/
{id}
/
token
Create or renew an OAuth token
curl --request POST \
  --url https://api.planetscale.com/v1/organizations/{organization}/oauth-applications/{id}/token \
  --header 'Authorization: <api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "client_id": "<string>",
  "client_secret": "<string>",
  "grant_type": "authorization_code",
  "code": "<string>",
  "redirect_uri": "<string>",
  "refresh_token": "<string>"
}'
{
  "id": "<string>",
  "name": "<string>",
  "display_name": "<string>",
  "token": "<string>",
  "plain_text_refresh_token": "<string>",
  "avatar_url": "<string>",
  "created_at": "<string>",
  "updated_at": "<string>",
  "expires_at": "<string>",
  "last_used_at": "<string>",
  "actor_id": "<string>",
  "actor_display_name": "<string>",
  "actor_type": "<string>",
  "service_token_accesses": [
    {
      "id": "<string>",
      "access": "<string>",
      "description": "<string>",
      "resource_name": "<string>",
      "resource_id": "<string>",
      "resource_type": "<string>",
      "resource": {
        "id": "<string>",
        "name": "<string>",
        "created_at": "<string>",
        "updated_at": "<string>",
        "deleted_at": "<string>"
      }
    }
  ],
  "oauth_accesses_by_resource": {
    "database": {
      "databases": [
        {
          "name": "<string>",
          "id": "<string>",
          "organization": "<string>",
          "url": "<string>"
        }
      ],
      "accesses": [
        {
          "name": "<string>",
          "description": "<string>"
        }
      ]
    },
    "organization": {
      "organizations": [
        {
          "name": "<string>",
          "id": "<string>",
          "url": "<string>"
        }
      ],
      "accesses": [
        {
          "name": "<string>",
          "description": "<string>"
        }
      ]
    },
    "branch": {
      "branches": [
        {
          "name": "<string>",
          "id": "<string>",
          "database": "<string>",
          "organization": "<string>",
          "url": "<string>"
        }
      ],
      "accesses": [
        {
          "name": "<string>",
          "description": "<string>"
        }
      ]
    },
    "user": {
      "users": [
        {
          "name": "<string>",
          "id": "<string>"
        }
      ],
      "accesses": [
        {
          "name": "<string>",
          "description": "<string>"
        }
      ]
    }
  }
}

Authorizations

Authorization
string
header
required

Path Parameters

organization
string
required

The name of the organization the OAuth application belongs to

id
string
required

The ID of the OAuth application

Body

application/json
client_id
string
required

The OAuth application's client ID

client_secret
string
required

The OAuth application's client secret

grant_type
enum<string>
required

Whether an OAuth grant code or a refresh token is being exchanged for an OAuth token

Available options:
authorization_code,
refresh_token
code
string

The OAuth grant code provided to your OAuth application's redirect URI. Required when grant_type is authorization_code

redirect_uri
string

The OAuth application's redirect URI. Required when grant_type is authorization_code

refresh_token
string

The refresh token from the original OAuth token grant. Required when grant_type is refresh_token

Response

Returns the created OAuth token

id
string
required

The ID of the service token

name
string
required

The name of the service token

display_name
string
required

The display name of the service token

token
string
required

The plain text token. Available only after create.

plain_text_refresh_token
string
required

The plain text refresh token. Available only after create.

avatar_url
string
required

The image source for the avatar of the service token

created_at
string
required

When the service token was created

updated_at
string
required

When the service token was last updated

expires_at
string
required

When the service token will expire

last_used_at
string
required

When the service token was last used

actor_id
string
required

The ID of the actor on whose behalf the service token was created

actor_display_name
string
required

The name of the actor on whose behalf the service token was created

actor_type
string
required

The type of the actor on whose behalf the service token was created

service_token_accesses
object[]
required
oauth_accesses_by_resource
object
required
I