I'm trying to use sandboxPublicTokenCreate() to get a public token to use in my tests, but I keeps returning a 400 error like:
data: {
display_message: null,
documentation_url: 'https://plaid.com/docs/?ref=error#invalid-input-errors',
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: '2yEEbS5QI993pZj',
suggested_action: null
}
I've followed the example docs at https://plaid.com/docs/api/sandbox/ and tried manually executing the request with Axios, with same result:
Here's my code:
import { Configuration, PlaidApi, PlaidEnvironments, Products, SandboxPublicTokenCreateRequest } from 'plaid'
/**
* Returns a public token we can use for testing tied to the Royal Bank of Plaid
*
* @returns {Promise<string>}
* @memberof BankAccountService
*/
public async getPublicTokenForTesting(): Promise<string> {
const institutionId = 'ins_117650'
const initialProducts = [Products.Assets, Products.Balance]
const publicTokenRequest: SandboxPublicTokenCreateRequest = {
institution_id: institutionId,
initial_products: initialProducts
}
try {
const CONFIG = new Configuration({
basePath: PlaidEnvironments[process.env.PLAID_ENV],
baseOptions: {
headers: {
'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
'PLAID-SECRET': process.env.PLAID_SECRET
}
}
})
const client = new PlaidApi(CONFIG)
const publicTokenResponse = await client.sandboxPublicTokenCreate(publicTokenRequest)
const publicToken = publicTokenResponse.data.public_token
return publicToken
} catch (e) {
console.error({ response: e.response })
}
Apologies, I was using Polly to record requests and it was replaying a bad response. Will close this as soon as SO lets me.