curl --request GET \
--url https://api.komerza.com/oauth2/{appId}/exchange/{code} \
--header 'Authorization: Bearer <token>'{
"success": true,
"message": "<string>",
"code": "<string>",
"data": "<string>"
}Exchanges an authorization code for an API key.
curl --request GET \
--url https://api.komerza.com/oauth2/{appId}/exchange/{code} \
--header 'Authorization: Bearer <token>'{
"success": true,
"message": "<string>",
"code": "<string>",
"data": "<string>"
}X-Client-Secret header for authentication instead
of the standard Authorization header.| Parameter | Type | Description |
|---|---|---|
appId | string | Your application’s Client ID |
code | string | The authorization code received from the callback |
| Header | Required | Description |
|---|---|---|
X-Client-Secret | Yes | Your application’s 72-character client secret |
User-Agent | Yes | Your application identifier |
{
"success": true,
"data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
data field contains a JWT API key that you can use to make authenticated API requests.
curl -X GET https://api.komerza.com/stores/STORE_ID \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "User-Agent: MyApp/1.0"
| Error | Description |
|---|---|
invalid_code | The authorization code is invalid or has already been used |
code_expired | The authorization code has expired (codes are valid for 1 minute) |
invalid_client_secret | The client secret is incorrect |
app_not_found | The application ID is invalid |
// 1. User clicks "Connect with Komerza" in your app
const authUrl = `https://dashboard.komerza.com/auth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&state=${randomState}`;
window.location.href = authUrl;
// 2. User authorizes on Komerza, redirected back to your app
// URL: https://myapp.com/callback?code=ENCRYPTED_CODE&state=randomState
// 3. Your backend exchanges the code for an API key
const response = await fetch(
`https://api.komerza.com/oauth2/${CLIENT_ID}/exchange/${code}`,
{
headers: {
"x-client-secret": process.env.CLIENT_SECRET,
"User-Agent": "MyApp/1.0",
},
}
);
const { data: apiKey } = await response.json();
// 4. Store the API key securely and use it for API calls
const stores = await fetch("https://api.komerza.com/stores", {
headers: {
Authorization: `Bearer ${apiKey}`,
"User-Agent": "MyApp/1.0",
},
});
Your API key goes here
The application ID.
The authorization code to exchange.
The object was successfully returned.
Represents a default generic response for API endpoints.
Indicates whether the operation or response was successful.
A descriptive message providing additional context or information about the response.
The error code (if there was an error) to use when referencing the error
Represents the data associated with a response.
Was this page helpful?