What's up team, I'm trying to use Plaid to automatically populate a Google Sheet with financial statements set up in my Plaid account. I've seen this done recently by some companies for a fee (e.g. <https://www.budgetsheet.net/>). I've also seen it done by developers a couple of years ago (see <https://github.com/hirefrank/plaid-txns-google-sheets>). This is what I want to do, but the Plaid API has updated since then to remove the public key from usage in place of a Link Token: <https://plaid.com/docs/link/link-token-migration-guide/>

The workflow is supposed to be as follows:

1. Make a request to create a link token with the client ID and secret.
2. Use the link token to open Link. In the onSuccess callback, send the temporary public\_token to your app's server.
3. Make a request to exchange the public\_token for a permanent access\_token and item\_id for the new Item.
4. Store the access\_token and use it to make product requests for your user's Item.

I can create the link\_token from the following call (the link token is at **responseJSON.link\_token**):

```
/************************************************************************************
 * 
 * Creating function to get access token
 * 
 ************************************************************************************/

function getLinkToken(CLIENT_ID, SECRET) {

  // Specify headers
  var headers = {
    'Content-Type': 'application/json',
  };

  // Build data for link token
  var data = {
    'client_id': CLIENT_ID,
    'secret': SECRET,
    "client_name": "ryanmcslomo",
    "products": ["auth", 'transactions'],
    "language": "en",
    "country_codes": ["US"],
    "user": {
      // "client_user_id": "unique-per-user",
      "client_user_id": "ryanmcslomo",
    },
  };

  // Build params
  var parameters = {
    'headers': headers,
    'payload': JSON.stringify(data),
    'method': 'post',
    'muteHttpExceptions': true,
  };

  // Call link token API with params
  var url = "https://development.plaid.com/link/token/create";
  var response = UrlFetchApp.fetch(url, parameters);
  var responseJSON = JSON.parse(response);

  //Return JSON containing Link Token
  return responseJSON;
}

```

But after that I'm unsure how to initialize the Link with a Link Token (much less grab the Public Token to be exchanged for an Access Token). When I try to pass the link token as the public token to authenticate, it (of course) fails:

```
  // Build data for access token
  var data2 = {
    'client_id': CLIENT_ID,
    'secret': SECRET,
    "public_token": responseJSON.link_token
  };

  // Build params
  var parameters2 = {
    'headers': headers,
    'payload': JSON.stringify(data2),
    'method': 'post',
    'muteHttpExceptions': true,
  };

  // Call API with params
  var url2 = "https://development.plaid.com/item/public_token/exchange";
  var response2 = UrlFetchApp.fetch(url2, parameters2);
  var response2JSON = JSON.parse(response2);

  // return JSON response with Link Token
  return response2JSON;
}

```

response2JSON:

```
{
display_message: null
documentation_url: "https://plaid.com/docs/?ref=error#invalid-input-errors"
error_code: "INVALID_PUBLIC_TOKEN"
error_message: 'provided token is the wrong type. expected "public", got "link"'
error_type: " INVALID_INPUT"
...
}

```

Any ideas? Not sure how to do this as Google Apps Script. Thank you for your help!

Other places I've looked:

* Stripe integration
	+ <https://stripe.com/docs/ach?__hstc=20629287.99a265337744294b740e0787aea508c4.1574726400918.1574726400919.1574726400920.1&__hssc=20629287.1.1574726400921&__hsfp=1895241284>
* Doing it in React
	+ <https://plaid.com/docs/quickstart/#making-api-requests>
* Token docs
	+ <https://plaid.com/docs/api/tokens/>
* SDK on GitHub
	+ <https://github.com/plaid/plaid-java/issues/105>