0

I've been trying to do an HTTP.post with data, but I keep getting a 401 response saying that one of the vars (client_id) is missing.

Code:

fetchPlaidAccounts: function (options) {
    this.unblock();
    response = HTTP.post(config.plaid.base_url + 'connect', {
        data: {
            client_id: config.plaid.client_id,
            secret: config.plaid.secret,
            username: options.username,
            password: options.password,
            type: options.institution,
            email: options.email,
            options: '{"login_only":true,"list":true}'
        },
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Access-Control-Allow-Origin': '*'
        }
    });
    return response;
}

I did a HTTP.get earlier and that worked just fine using params instead of data.

I also console.log’d all the variables, and they all have values.

So, what am I doing wrong here?

Nate Ritter
  • 2,386
  • 3
  • 20
  • 28

2 Answers2

2

I answered my own question.

Come to find out, I don't need to add headers when it's in the server side. Those headers should only be needed when you're running calls on the client side.

So, the final call looks like this:

fetchPlaidAccounts: function (options) {
    this.unblock();
    var d = {
        client_id: config.plaid.client_id,
        secret   : config.plaid.secret,
        username : options.username,
        password : options.password,
        email    : options.email,
        type     : options.institution,
        options: '{"login_only":true,"list":true}'
    };
    var response = HTTP.post(config.plaid.base_url + 'connect', { data: d });
    return response;
}
Nate Ritter
  • 2,386
  • 3
  • 20
  • 28
0

Try using params instead of data:

HTTP.post(config.plaid.base_url + 'connect', {
    params: {
        ...
    }

data sends the values as JSON encoded as the body during the POST. Params sends them as multi/part form data, which is what I suspect the API uses.

Tarang
  • 75,157
  • 39
  • 215
  • 276
  • Unfortunately that response with a 404 `Error: failed [404] { "code": 1601, "message": "product not available", "resolve": "This product is not yet available for this institution." }` – Nate Ritter Nov 07 '14 at 03:08
  • @nateritter It might worth be checking out the API with `curl`. If you got that error it means its an issue with your input data and not the code. – Tarang Nov 07 '14 at 04:00
  • I did that, and it worked under curl, but I finally figured out the issue. Will post the answer. Thanks for the help @Akshat. – Nate Ritter Nov 07 '14 at 17:24