Search code examples
plaid

How to properly format a public token when using the Plaid API exchangePublicToken method


I receive this error when trying to exchange a public token for an access token with the Plaid API:

{ display_message: null,
error_code: ‘INVALID_PUBLIC_TOKEN‘,
error_message: ‘provided public token is in an invalid format. expected format: public-<environment>-<identifier>’,
error_type: ‘INVALID_INPUT‘,
request_id: ‘vVGLl’,
status_code: 400 }

The token format that is received in the onSucceess callback and that I am passing to exchangePublicToken is as follows:

beb195c7ab7f2f3ed343f822250cc574d42f536e14be2b11a68a31b7dbc6944c34df45ce7226f1dbc1a6ea152a5448323229dfae333a50c1137cf5ac3d909f18

The error states that the expected format of the public token is public-<environment>-<identifier>. Can anyone clarify what the identifier refers to?

How do I properly format the public token to exchange it for an access token?


Solution

  • It looks like you might simply be mixing environments between your Link and Exchange calls.

    If you look at the relevant area in Plaid's docs, you'll see that the tokens in the latest Plaid API on sandbox should look like this:

    Public Token: public-sandbox-fb7cca4a-82e6-4707

    Access Token: access-sandbox-7c69d345-fd46-461f

    Make sure that both Plaid Link and whatever API calls you're making are using the same environment (i.e. sandbox, development or production). Another problem could be that you're using the legacy API with Link and the new API with the exchange call.