JavaScript
import Finch from '@tryfinch/finch-api';
const client = new Finch();
const createAccessTokenResponse = await client.accessTokens.create({ code: 'code' });
console.log(createAccessTokenResponse.connection_id);from finch import Finch
client = Finch()
create_access_token_response = client.access_tokens.create(
code="code",
)
print(create_access_token_response.connection_id)package main
import (
"context"
"fmt"
"github.com/Finch-API/finch-api-go/v2"
"github.com/Finch-API/finch-api-go/v2/option"
)
func main() {
client := finchgo.NewClient(
option.WithAccessToken("My Access Token"),
option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"),
option.WithClientSecret("My Client Secret"),
)
createAccessTokenResponse, err := client.AccessTokens.New(context.TODO(), finchgo.AccessTokenNewParams{
Code: finchgo.F("code"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", createAccessTokenResponse.ConnectionID)
}
package com.tryfinch.api.example;
import com.tryfinch.api.client.FinchClient;
import com.tryfinch.api.client.okhttp.FinchOkHttpClient;
import com.tryfinch.api.models.AccessTokenCreateParams;
import com.tryfinch.api.models.CreateAccessTokenResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
FinchClient client = FinchOkHttpClient.builder()
.fromEnv()
.accessToken("My Access Token")
.build();
AccessTokenCreateParams params = AccessTokenCreateParams.builder()
.code("code")
.build();
CreateAccessTokenResponse createAccessTokenResponse = client.accessTokens().create(params);
}
}package com.tryfinch.api.example
import com.tryfinch.api.client.FinchClient
import com.tryfinch.api.client.okhttp.FinchOkHttpClient
import com.tryfinch.api.models.AccessTokenCreateParams
import com.tryfinch.api.models.CreateAccessTokenResponse
fun main() {
val client: FinchClient = FinchOkHttpClient.builder()
.fromEnv()
.accessToken("My Access Token")
.build()
val params: AccessTokenCreateParams = AccessTokenCreateParams.builder()
.code("code")
.build()
val createAccessTokenResponse: CreateAccessTokenResponse = client.accessTokens().create(params)
}require "finch_api"
finch = FinchAPI::Client.new(
access_token: "My Access Token",
client_id: "4ab15e51-11ad-49f4-acae-f343b7794375",
client_secret: "My Client Secret"
)
create_access_token_response = finch.access_tokens.create(code: "code")
puts(create_access_token_response)curl --request POST \
--url https://api.tryfinch.com/auth/token \
--header 'Content-Type: <content-type>' \
--header 'Finch-API-Version: <finch-api-version>' \
--data '
{
"code": "<string>",
"client_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"client_secret": "<string>",
"redirect_uri": "<string>"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tryfinch.com/auth/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 => json_encode([
'code' => '<string>',
'client_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'client_secret' => '<string>',
'redirect_uri' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"Finch-API-Version: <finch-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"access_token": "7e965183-9332-423c-9259-3edafb332ad2",
"token_type": "bearer",
"connection_id": "bc3a2af9-ce03-46c4-9142-81abe789c64d",
"customer_id": "1234567890",
"customer_name": "Acme Inc",
"account_id": "ac3a2af9-ce03-46c4-9142-81abe789c64d",
"client_type": "production",
"company_id": "4ab15e51-11ad-49f4-acae-f343b7794375",
"connection_type": "provider",
"products": [
"directory",
"employment",
"individual"
],
"provider_id": "gusto",
"entity_ids": [
"550e8400-e29b-41d4-a716-446655440000",
"6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"6ba7b811-9dad-11d1-80b4-00c04fd430c8"
]
}{
"code": 400,
"name": "bad_request",
"finch_code": "invalid_request",
"message": "Invalid grant: authorization code is invalid."
}Management
Create Access Token
Exchange the authorization code for an access token
POST
/
auth
/
token
JavaScript
import Finch from '@tryfinch/finch-api';
const client = new Finch();
const createAccessTokenResponse = await client.accessTokens.create({ code: 'code' });
console.log(createAccessTokenResponse.connection_id);from finch import Finch
client = Finch()
create_access_token_response = client.access_tokens.create(
code="code",
)
print(create_access_token_response.connection_id)package main
import (
"context"
"fmt"
"github.com/Finch-API/finch-api-go/v2"
"github.com/Finch-API/finch-api-go/v2/option"
)
func main() {
client := finchgo.NewClient(
option.WithAccessToken("My Access Token"),
option.WithClientID("4ab15e51-11ad-49f4-acae-f343b7794375"),
option.WithClientSecret("My Client Secret"),
)
createAccessTokenResponse, err := client.AccessTokens.New(context.TODO(), finchgo.AccessTokenNewParams{
Code: finchgo.F("code"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", createAccessTokenResponse.ConnectionID)
}
package com.tryfinch.api.example;
import com.tryfinch.api.client.FinchClient;
import com.tryfinch.api.client.okhttp.FinchOkHttpClient;
import com.tryfinch.api.models.AccessTokenCreateParams;
import com.tryfinch.api.models.CreateAccessTokenResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
FinchClient client = FinchOkHttpClient.builder()
.fromEnv()
.accessToken("My Access Token")
.build();
AccessTokenCreateParams params = AccessTokenCreateParams.builder()
.code("code")
.build();
CreateAccessTokenResponse createAccessTokenResponse = client.accessTokens().create(params);
}
}package com.tryfinch.api.example
import com.tryfinch.api.client.FinchClient
import com.tryfinch.api.client.okhttp.FinchOkHttpClient
import com.tryfinch.api.models.AccessTokenCreateParams
import com.tryfinch.api.models.CreateAccessTokenResponse
fun main() {
val client: FinchClient = FinchOkHttpClient.builder()
.fromEnv()
.accessToken("My Access Token")
.build()
val params: AccessTokenCreateParams = AccessTokenCreateParams.builder()
.code("code")
.build()
val createAccessTokenResponse: CreateAccessTokenResponse = client.accessTokens().create(params)
}require "finch_api"
finch = FinchAPI::Client.new(
access_token: "My Access Token",
client_id: "4ab15e51-11ad-49f4-acae-f343b7794375",
client_secret: "My Client Secret"
)
create_access_token_response = finch.access_tokens.create(code: "code")
puts(create_access_token_response)curl --request POST \
--url https://api.tryfinch.com/auth/token \
--header 'Content-Type: <content-type>' \
--header 'Finch-API-Version: <finch-api-version>' \
--data '
{
"code": "<string>",
"client_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"client_secret": "<string>",
"redirect_uri": "<string>"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tryfinch.com/auth/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 => json_encode([
'code' => '<string>',
'client_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'client_secret' => '<string>',
'redirect_uri' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"Finch-API-Version: <finch-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"access_token": "7e965183-9332-423c-9259-3edafb332ad2",
"token_type": "bearer",
"connection_id": "bc3a2af9-ce03-46c4-9142-81abe789c64d",
"customer_id": "1234567890",
"customer_name": "Acme Inc",
"account_id": "ac3a2af9-ce03-46c4-9142-81abe789c64d",
"client_type": "production",
"company_id": "4ab15e51-11ad-49f4-acae-f343b7794375",
"connection_type": "provider",
"products": [
"directory",
"employment",
"individual"
],
"provider_id": "gusto",
"entity_ids": [
"550e8400-e29b-41d4-a716-446655440000",
"6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"6ba7b811-9dad-11d1-80b4-00c04fd430c8"
]
}{
"code": 400,
"name": "bad_request",
"finch_code": "invalid_request",
"message": "Invalid grant: authorization code is invalid."
}Headers
Body
application/json
Response
Access Token
Was this page helpful?