curl --request POST \
--url https://app.trelica.com/connect/token \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'scope=<string>' \
--data 'code=<string>' \
--data 'redirect_uri=<string>' \
--data 'refresh_token=<string>'const encodedParams = new URLSearchParams();
encodedParams.append('scope', '<string>');
encodedParams.append('code', '<string>');
encodedParams.append('redirect_uri', '<string>');
encodedParams.append('refresh_token', '<string>');
const url = 'https://app.trelica.com/connect/token';
const options = {
method: 'POST',
headers: {
Authorization: 'Basic <encoded-value>',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: encodedParams
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://app.trelica.com/connect/token"
payload = {
"scope": "<string>",
"code": "<string>",
"redirect_uri": "<string>",
"refresh_token": "<string>"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.trelica.com/connect/token"
payload := strings.NewReader("scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}using RestSharp;
var options = new RestClientOptions("https://app.trelica.com/connect/token");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Basic <encoded-value>");
request.AddParameter("scope", "<string>");
request.AddParameter("code", "<string>");
request.AddParameter("redirect_uri", "<string>");
request.AddParameter("refresh_token", "<string>");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
HttpResponse<String> response = Unirest.post("https://app.trelica.com/connect/token")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trelica.com/connect/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E",
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}$headers=@{}
$headers.Add("Authorization", "Basic <encoded-value>")
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
$response = Invoke-WebRequest -Uri 'https://app.trelica.com/connect/token' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded' -Body 'scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E'require 'uri'
require 'net/http'
url = URI("https://app.trelica.com/connect/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E"
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "Users.Read offline_access",
"refresh_token": "8xLOxBtZp8..."
}{
"error": "invalid_client"
}Request an access token
Exchanges client credentials (or an authorization code / refresh token) for an access token. The client ID and secret are sent via HTTP Basic authentication. The body is application/x-www-form-urlencoded.
- Client Credentials:
grant_type=client_credentials(optionalscope). - Authorization Code:
grant_type=authorization_codewithcodeandredirect_uri. - Refresh:
grant_type=refresh_tokenwithrefresh_token(requires theoffline_accessscope).
curl --request POST \
--url https://app.trelica.com/connect/token \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'scope=<string>' \
--data 'code=<string>' \
--data 'redirect_uri=<string>' \
--data 'refresh_token=<string>'const encodedParams = new URLSearchParams();
encodedParams.append('scope', '<string>');
encodedParams.append('code', '<string>');
encodedParams.append('redirect_uri', '<string>');
encodedParams.append('refresh_token', '<string>');
const url = 'https://app.trelica.com/connect/token';
const options = {
method: 'POST',
headers: {
Authorization: 'Basic <encoded-value>',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: encodedParams
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));import requests
url = "https://app.trelica.com/connect/token"
payload = {
"scope": "<string>",
"code": "<string>",
"redirect_uri": "<string>",
"refresh_token": "<string>"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.trelica.com/connect/token"
payload := strings.NewReader("scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}using RestSharp;
var options = new RestClientOptions("https://app.trelica.com/connect/token");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Basic <encoded-value>");
request.AddParameter("scope", "<string>");
request.AddParameter("code", "<string>");
request.AddParameter("redirect_uri", "<string>");
request.AddParameter("refresh_token", "<string>");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
HttpResponse<String> response = Unirest.post("https://app.trelica.com/connect/token")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trelica.com/connect/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E",
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}$headers=@{}
$headers.Add("Authorization", "Basic <encoded-value>")
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
$response = Invoke-WebRequest -Uri 'https://app.trelica.com/connect/token' -Method POST -Headers $headers -ContentType 'application/x-www-form-urlencoded' -Body 'scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E'require 'uri'
require 'net/http'
url = URI("https://app.trelica.com/connect/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "scope=%3Cstring%3E&code=%3Cstring%3E&redirect_uri=%3Cstring%3E&refresh_token=%3Cstring%3E"
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "Users.Read offline_access",
"refresh_token": "8xLOxBtZp8..."
}{
"error": "invalid_client"
}Authorizations
HTTP Basic authentication: the client ID and client secret, joined with a colon and Base64-encoded (RFC 7617).
Body
The OAuth 2.0 grant type.
client_credentials, authorization_code, refresh_token Space-separated scopes to request. Defaults to all scopes configured for the app.
The authorization code (Authorization Code flow).
Must match the redirect URI from the authorization request (Authorization Code flow).
The refresh token (Refresh flow).
Response
The access token.
The access token to send as a bearer token on API requests.
The token type; always Bearer.
The token lifetime in seconds (access tokens expire after ~60 minutes).
The space-separated scopes granted.
A refresh token (Authorization Code flow only, when offline_access was requested).
Was this page helpful?