Skip to main content
POST
/
oauth
/
token
JavaScript
import Telnyx from 'telnyx';

const client = new Telnyx();

const response = await client.oauth.token({ grant_type: 'client_credentials' });

console.log(response.access_token);
from telnyx import Telnyx

client = Telnyx()
response = client.oauth.token(
grant_type="client_credentials",
)
print(response.access_token)
package main

import (
"context"
"fmt"

"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)

func main() {
client := telnyx.NewClient(
option.WithClientID("My Client ID"),
option.WithClientSecret("My Client Secret"),
)
response, err := client.OAuth.Token(context.TODO(), telnyx.OAuthTokenParams{
GrantType: telnyx.OAuthTokenParamsGrantTypeClientCredentials,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.AccessToken)
}
package com.telnyx.sdk.example;

import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.oauth.OAuthTokenParams;
import com.telnyx.sdk.models.oauth.OAuthTokenResponse;

public final class Main {
private Main() {}

public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();

OAuthTokenParams params = OAuthTokenParams.builder()
.grantType(OAuthTokenParams.GrantType.CLIENT_CREDENTIALS)
.build();
OAuthTokenResponse response = client.oauth().token(params);
}
}
require "telnyx"

telnyx = Telnyx::Client.new(client_id: "My Client ID", client_secret: "My Client Secret")

response = telnyx.oauth.token(grant_type: :client_credentials)

puts(response)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;

$client = new Client(
clientID: getenv('TELNYX_CLIENT_ID') ?: 'My Client ID',
clientSecret: getenv('TELNYX_CLIENT_SECRET') ?: 'My Client Secret',
);

try {
$response = $client->oauth->token(
grantType: 'client_credentials',
clientID: 'client_id',
clientSecret: 'client_secret',
code: 'code',
codeVerifier: 'code_verifier',
redirectUri: 'https://example.com',
refreshToken: 'refresh_token',
scope: 'admin',
);

var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}
telnyx oauth token \
--client-id 'My Client ID' \
--client-secret 'My Client Secret' \
--grant-type client_credentials
curl --request POST \
--url https://api.telnyx.com/v2/oauth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data scope=admin \
--data 'code=<string>' \
--data 'redirect_uri=<string>' \
--data 'code_verifier=<string>' \
--data 'refresh_token=<string>' \
--data 'client_id=<string>' \
--data 'client_secret=<string>'
{
  "access_token": "<string>",
  "token_type": "Bearer",
  "expires_in": 123,
  "scope": "<string>",
  "refresh_token": "<string>"
}

Body

grant_type
enum<string>
required

OAuth 2.0 grant type

Available options:
client_credentials,
authorization_code,
refresh_token
scope
string

Space-separated list of requested scopes (for client_credentials)

Example:

"admin"

code
string

Authorization code (for authorization_code flow)

redirect_uri
string<uri>

Redirect URI (for authorization_code flow)

code_verifier
string

PKCE code verifier (for authorization_code flow)

refresh_token
string

Refresh token (for refresh_token flow)

client_id
string

OAuth client ID (if not using HTTP Basic auth)

client_secret
string

OAuth client secret (if not using HTTP Basic auth)

Response

Token response

access_token
string
required

The access token

token_type
enum<string>
required

Token type

Available options:
Bearer
expires_in
integer
required

Token lifetime in seconds

scope
string

Space-separated list of granted scopes

refresh_token
string

Refresh token (if applicable)