TomorrowIdeas / plaid-sdk-php

PHP bindings for the Plaid API
MIT License
111 stars 42 forks source link

Bad Request #38

Closed eldan88 closed 3 years ago

eldan88 commented 3 years ago

Hi,

I am trying to get a list of transactions and it keeps saying bad request. Not sure what I am doing wrong here. Below is my code


        $start   = new DateTime("2021-05-01",new DateTimeZone("America/New_York"));
        $end     = new DateTime("2021-05-20",new DateTimeZone("America/New_York"));

        $transactions = $client->transactions->list($token,$start,$end);
brentscheffler commented 3 years ago

Can you paste the contents of the raw response from Plaid?

try {
    $transactions = $client->transactions->list($token,$start,$end);
} catch (\Exception $e) {
    die(print_r($e->getResponse(),true));
}
eldan88 commented 3 years ago

Thanks for the reply.

INVALID_ACCESS_TOKEN [error_message] => provided token is the wrong type. expected "access", got "public" [error_type] => INVALID_INPUT

This is what I am using to get a token $response = $client->sandbox->createPublicToken("ins_3",array("transactions"));

    $token  =  $response->public_token;
brentscheffler commented 3 years ago

I think your issue is stated in the response:

provided token is the wrong type. expected "access", got "public"

I would recommend reading over Plaid's API documentation, particularly around token management: https://plaid.com/docs/api/tokens/

eldan88 commented 3 years ago

I dont get it. That is the only token you provide on your library

brentscheffler commented 3 years ago

Each item will have its own access token, I believe you should be using that token. Again, I think reading the API documentation for Plaid and how their workflow and endpoints behave would clear up a lot of the confusion.

brentscheffler commented 3 years ago

Here's a direct link to their documentation on how the public token to access token exchange needs to happen:

https://plaid.com/docs/api/tokens/#token-exchange-flow

For example, with a public token you would call:

$access_token_response = $plaid->items->exchangeToken($public_token);

$access_token = $access_token_response->access_token;
eldan88 commented 3 years ago

I have tried doing what you mentioned and I am getting this message PRODUCT_NOT_READY [error_message] => the requested product is not yet ready. please provide a webhook or try the request again later