OAuth token endpoint
Exchange authorization code, client credentials, or refresh token for access token
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_credentialscurl --request POST \
--url https://api.telnyx.com/v2/oauth/token \
--header 'Authorization: Bearer <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": 0,
"scope": "string",
"refresh_token": "string"
}Authorizations
OAuth 2.0 authentication for Telnyx API and MCP integrations
Body
application/x-www-form-urlencodedapplication/json
OAuth 2.0 grant type
Available options:
client_credentials, authorization_code, refresh_token Space-separated list of requested scopes (for client_credentials)
Example:
"admin"
Authorization code (for authorization_code flow)
Redirect URI (for authorization_code flow)
PKCE code verifier (for authorization_code flow)
Refresh token (for refresh_token flow)
OAuth client ID (if not using HTTP Basic auth)
OAuth client secret (if not using HTTP Basic auth)
Was this page helpful?
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_credentialscurl --request POST \
--url https://api.telnyx.com/v2/oauth/token \
--header 'Authorization: Bearer <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": 0,
"scope": "string",
"refresh_token": "string"
}