Reputation: 9
I’m working on integrating the Plaid API into my Python app to manage transactions from connected bank accounts. I’m currently testing this using the Plaid sandbox environment, but I keep running into issues when trying to exchange the public token for an access token.
Generated a link token successfully using my client ID and secret.
Simulated a user connecting a bank account using the sandbox credentials (user_good
and pass_good
).
After completing the Plaid Link flow, I received a public token.
Now, I’m trying to exchange that public token for an access token using the following code:
from plaid.api import plaid_api
from plaid.model.item_public_token_exchange_request import ItemPublicTokenExchangeRequest
from plaid import ApiClient
from plaid.configuration import Configuration
import os
# Set up Plaid configuration
configuration = Configuration(
host="https://sandbox.plaid.com",
api_key={
'clientId': os.getenv('PLAID_CLIENT_ID'),
'secret': os.getenv('PLAID_SECRET'),
}
)
api_client = ApiClient(configuration)
client = plaid_api.PlaidApi(api_client)
# Exchange public token for access token
def exchange_public_token(public_token):
request = ItemPublicTokenExchangeRequest(public_token=public_token)
response = client.item_public_token_exchange(request)
return response['access_token']
# Public token generated from Plaid Link
public_token = "my_public_token_here"
# Attempt to exchange for access token
access_token = exchange_public_token(public_token)
print(f"Access Token: {access_token}")
When I try to exchange the public token, I get the following error:
plaid.exceptions.ApiException: Status Code: 400
Reason: Bad Request
HTTP response body: {
"error_code": "INVALID_PUBLIC_TOKEN",
"error_message": "could not find matching public token due to client ID mismatch"
}
I’ve double-checked that the client ID and secret in my environment variables match the ones in my Plaid dashboard.
The link token generation works fine, and the public token is generated after the user links a sandbox bank account.
I’ve regenerated the link token and gone through the process multiple times to ensure that I’m using the correct public token, but the error persists.
Has anyone encountered a similar issue or knows how to resolve this client ID mismatch with the public token in the sandbox environment?
Upvotes: 0
Views: 38