Jepf
Jepf

Reputation: 85

Plaid API php cURL not sending post data

I am trying to translate the below cURL to php cURL:

$ curl -X POST https://tartan.plaid.com/exchange_token \

-d client_id="$plaid_client_id" \ -d secret="$plaid_secret" \ -d public_token="$public_token_from_plaid_link_module"

using this code:

    $data = array(
        "cliend_id"=>"test_id",
        "secret"=>"test_secret",
        "public_token"=>"test,fidelity,connected");
    $string = http_build_query($data);

    echo $string;

    //initialize session
    $ch=curl_init("https://tartan.plaid.com/exchange_token");

    //set options
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    //execute session
    $exchangeToken = curl_exec($ch);
    echo $exchangeToken;
    //close session
    curl_close($ch);

and I am getting this response:

cliend_id=test_id&secret=test_secret&public_token=test%2Cfidelity%2Cconnected{ "code": 1100, "message": "client_id missing", "resolve": "Include your Client ID so we know who you are." }

I am not sure what is wrong with my format that is keeping plaid from recognizing the client_id portion of the post. For further reference, I have more detail below.

The below is taken from the plaid site that can be found by searching "plaid api quickstart":


Reference /exchange_token Endpoint

The /exchange_token endpoint is available in both the tartan and production environments. Method Endpoint Required Parameters Optional Parameters POST /exchange_token client_id, secret, public_token account_id

The /exchange_token endpoint has already been integrated into the plaid-node, plaid-go, plaid-ruby, and plaid-python client libraries. Support for plaid-java is coming soon.

If you are working with a library that does not yet support the /exchange_token endpoint you can simply make a standard HTTP request:

$ curl -X POST https://tartan.plaid.com/exchange_token \

-d client_id="$plaid_client_id" \ -d secret="$plaid_secret" \ -d public_token="$public_token_from_plaid_link_module"

For a valid request, the API will return a JSON response similar to:

{ "access_token": "foobar_plaid_access_token" }


Upvotes: 0

Views: 942

Answers (1)

Alonso Urbano
Alonso Urbano

Reputation: 2263

The problem is you are sending cliend_id but the server expects client_id:

$data = array(
    "client_id"=>"test_id", // Use client_id instead of cliend_id
    "secret"=>"test_secret",
    "public_token"=>"test,fidelity,connected");

Upvotes: 2

Related Questions