Dianté Brown
Dianté Brown

Reputation: 9

Issues integrating Plaid API into my Python script (Client ID mismatch with public token)

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.

What I’ve done so far:

  1. Generated a link token successfully using my client ID and secret.

  2. Simulated a user connecting a bank account using the sandbox credentials (user_good and pass_good).

  3. After completing the Plaid Link flow, I received a public token.

  4. 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}")
    

Problem:

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"
}

Steps I’ve Tried:

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

Answers (0)

Related Questions