Exchange or refresh tokens
curl --request POST \
--url https://api.bachs.io/v1/connect/oauth/token \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"grant_type": "authorization_code",
"client_id": "app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz",
"redirect_uri": "https://platform.example/bachs/callback",
"code": "dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI",
"code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'authorization_code',
client_id: 'app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz',
redirect_uri: 'https://platform.example/bachs/callback',
code: 'dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI',
code_verifier: 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'
})
};
fetch('https://api.bachs.io/v1/connect/oauth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.bachs.io/v1/connect/oauth/token"
payload = {
"grant_type": "authorization_code",
"client_id": "app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz",
"redirect_uri": "https://platform.example/bachs/callback",
"code": "dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI",
"code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.bachs.io/v1/connect/oauth/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"client_id\": \"app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz\",\n \"redirect_uri\": \"https://platform.example/bachs/callback\",\n \"code\": \"dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI\",\n \"code_verifier\": \"dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"account_id": "acct_8Qz4k2Bp6NvR7dHc",
"livemode": false,
"token_type": "Bearer",
"access_token": "sk_sandbox_9cfa0c7e_o7ozvw-rhGzcnD214SWK33C2C1s44Q4UA3kTmxRWcZs",
"refresh_token": "9w42ebfsXyghxLDgN0ZM0h6tYYyjrW0nXUTvVLnup2g",
"expires_in": 3600,
"scope": "payments:read",
"webhook_endpoint_id": "whe_7Qm2cN6vR4pK8dLs",
"webhook_signing_secret": "whsec_68e0eec57fcfdba7aff2465787b23ceca5325257d72c5426aa735305ce193da3"
}{
"error": "invalid_grant",
"error_description": "The authorization code is not valid."
}{
"error": "invalid_client",
"error_description": "The client could not be authenticated."
}{
"detail": "API key does not have permission for this operation",
"error_code": "FORBIDDEN"
}{
"detail": "Rate limit exceeded. Please retry after a few seconds.",
"error_code": "TOO_MANY_REQUESTS"
}Bachs Apps
Exchange or refresh tokens
Swaps an approved code for scoped access to a business, or rotates the current refresh token. Authenticate with your app’s client secret, as HTTP Basic or client_secret in the body. Apps moved from Connect with Bachs may use the owner’s secret key with connected_accounts:write until their first call with a client secret. Each refresh moves the connection’s end to 90 days from now. See Connect a business.
POST
/
v1
/
connect
/
oauth
/
token
Exchange or refresh tokens
curl --request POST \
--url https://api.bachs.io/v1/connect/oauth/token \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"grant_type": "authorization_code",
"client_id": "app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz",
"redirect_uri": "https://platform.example/bachs/callback",
"code": "dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI",
"code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'authorization_code',
client_id: 'app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz',
redirect_uri: 'https://platform.example/bachs/callback',
code: 'dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI',
code_verifier: 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'
})
};
fetch('https://api.bachs.io/v1/connect/oauth/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.bachs.io/v1/connect/oauth/token"
payload = {
"grant_type": "authorization_code",
"client_id": "app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz",
"redirect_uri": "https://platform.example/bachs/callback",
"code": "dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI",
"code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.bachs.io/v1/connect/oauth/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"client_id\": \"app_9Kd2Mw7Qx1Lr5Tn8Vb3Hs6Pz\",\n \"redirect_uri\": \"https://platform.example/bachs/callback\",\n \"code\": \"dQ6Bt0y2QmJc_XO-x-zZS1POIRsOPdCmDueYpYBEvyI\",\n \"code_verifier\": \"dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"account_id": "acct_8Qz4k2Bp6NvR7dHc",
"livemode": false,
"token_type": "Bearer",
"access_token": "sk_sandbox_9cfa0c7e_o7ozvw-rhGzcnD214SWK33C2C1s44Q4UA3kTmxRWcZs",
"refresh_token": "9w42ebfsXyghxLDgN0ZM0h6tYYyjrW0nXUTvVLnup2g",
"expires_in": 3600,
"scope": "payments:read",
"webhook_endpoint_id": "whe_7Qm2cN6vR4pK8dLs",
"webhook_signing_secret": "whsec_68e0eec57fcfdba7aff2465787b23ceca5325257d72c5426aa735305ce193da3"
}{
"error": "invalid_grant",
"error_description": "The authorization code is not valid."
}{
"error": "invalid_client",
"error_description": "The client could not be authenticated."
}{
"detail": "API key does not have permission for this operation",
"error_code": "FORBIDDEN"
}{
"detail": "Rate limit exceeded. Please retry after a few seconds.",
"error_code": "TOO_MANY_REQUESTS"
}Authorizations
AppClientAuthApiKeyAuth
Your app's client_id as the username and its client secret (appsk_live_... or appsk_test_...) as the password. You can send client_secret in the body instead. See Connect a business.
Body
application/jsonapplication/x-www-form-urlencoded
Response
Scoped business credentials, or the legacy account reference. Tokens are never returned by the browser callback.

