Search code examples
javascriptnode.jsplaid

Plaid's LinkTokenCreate giving 400 error in node.js


Is anyone else having problems with Plaid's linkTokenCreate method? I'm using node.js as the backend and when I run it alongside the frontend, the error starts on the line involving this function.

Even when I use the standard quickstart options, I still get the same 400 bad request error.

This is the backend code, same as the quickstart. I'm just testing for the link token, so its the only route I've defined.

app.post('/create_link_token', function (request, response, next)  {
    console.log('HI THERE')
    Promise.resolve()
    .then(async function () {
        const configs = {
            user: {
                //this should be a unique id for the current user.
                client_user_id: 'user-id',
            },
            client_name: 'Plaid Quickstart', 
            products: PLAID_PRODUCTS, 
            country_codes: PLAID_COUNTRY_CODES, 
            language: 'en',
        };

        console.log(configs);

        // if (PLAID_REDIRECT_URI !== '') {
        //     configs.redirect_uri = PLAID_REDIRECT_URI;
        // };

        const createTokenResponse = await client.linkTokenCreate(configs);
        console.log(createTokenResponse);
        prettyPrintResponse(createTokenResponse);
        response.json(createTokenResponse.data);
        
    })
    .catch(next);
});

and this is the error:

Error: Request failed with status code 400
    at createError (C:\Users\MyComputer\Desktop\mukadi\plaid-integration\backend\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\MyComputer\Desktop\mukadi\plaid-integration\backend\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\Users\MyComputer\Desktop\mukadi\plaid-integration\backend\node_modules\axios\lib\adapters\http.js:269:11)      
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)


Solution

  • Might be silly - but when I got this exact error it was because we didn't register our URI in our plaid dashboard.

    Register your redirect URI:

    Sign in to the Plaid Dashboard and go to the Team Settings -> API page. Next to Allowed redirect URIs click Configure then Add New URI. Enter your redirect URI, which you must also set up as a Universal Link for your application, for example: https://app.example.com/plaid/. Click Save Changes.