Saturday, 22 April 2017

Unable to exchange public_token for an access_token with Plaid API

I'm using Plaid Link on the client and Node on the server. The Plaid item is successfully created with Plaid Link and returns a public_token. I then hit an endpoint on the server that uses the Plaid client to call plaidClient.exchangePublicToken(public_token).

Every single time I try to exchange the public_token, I receive a error without any details that simply states Could not exchange public_token!.

I have deducted that the most likely reason for this error is a problem with my plaidClient. All other functionality seems to be working until I try to use the plaidClient to call exchangePublicToken.

I have been trying to get past this issue for days and would really appreciate any insight into what might be preventing me from exchanging my public_tokens.

Below is the server-side code I'm using to perform the token exchange.

var express = require('express');
var router = express.Router();
var bodyParser = require('body-parser');
var plaid = require('plaid');

// fake keys for this example
var PLAID_CLIENT_ID = '123123123123';
var PLAID_SECRET = '123123123123123';
var PLAID_PUBLIC_KEY = '123123123123123';
var PLAID_ENV = 'development';

// Initialize the Plaid plaidClient
var plaidClient = new plaid.Client(
    PLAID_CLIENT_ID,
    PLAID_SECRET,
    PLAID_PUBLIC_KEY,
    plaid.environments[PLAID_ENV]
);

router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));

router.post('/authenticate_item', function(req, res, next) {
  var accountPublicToken = req.body.public_token;
  plaidClient.exchangePublicToken(accountPublicToken, function(error, tokenResponse) {
    if (error != null) {
        var msg = 'Could not exchange public_token!';
        console.log(msg + '\n' + error);
        return res.json({error: msg});
    }

    var accessToken = tokenResponse.access_token;
    console.log('Access Token: ' + accessToken);

  });
});



via Trey Granderson

No comments:

Post a Comment