auth_exchange_code
Exchange an OAuth authorization code for access and refresh tokens to finish connecting FreshBooks. Call once with the code and state from the redirect to store credentials and enable API access.
Instructions
Exchange an OAuth authorization code for access and refresh tokens, completing the FreshBooks connection.
WHEN TO USE:
Immediately after the user visits the auth_get_url link and is redirected with a code
Only call once per code — codes expire quickly (typically 60 seconds)
REQUIRED:
code (string): The authorization code from the FreshBooks redirect URL. Example: "eyJhbGci..."
state (string): The state value returned by auth_get_url — must match to prevent CSRF. Example: "abc123xyz"
RETURNS: { success: true, userId, accountId, businessId, email, expiresAt } Tokens are stored locally; all subsequent tool calls use them automatically.
ERRORS:
Expired or invalid code → restart with auth_get_url
State mismatch → CSRF protection triggered → restart with auth_get_url
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Authorization code from the FreshBooks OAuth redirect URL. Example: "eyJhbGci..." | |
| state | Yes | CSRF state token returned by auth_get_url; must match the value from that call. Example: "abc123xyz" |