'Plaid API get Access Token java android

I am a beginner with communicating with APIs and I am currently working with the Plaid API in order to retrieve transaction data for an android application. Currently, I have successfully integrated with the Plaid Link and can obtain public tokens through the app, however I am now having trouble exchanging the public token for the access token. I obtain the public token from here:

private ActivityResultLauncher<LinkTokenConfiguration> linkAccountToPlaid = registerForActivityResult(
      new OpenPlaidLink(),
      result -> {
        if (result instanceof LinkSuccess) {
            //Exchange public token for persistent access token

I believe the following code on the server is used to exchange the public token:

app.post('/api/set_access_token', function (request, response, next) {
  PUBLIC_TOKEN = request.body.public_token;
  Promise.resolve()
    .then(async function () {
      const tokenResponse = await client.itemPublicTokenExchange({
        public_token: PUBLIC_TOKEN,
      });
      prettyPrintResponse(tokenResponse);
      ACCESS_TOKEN = tokenResponse.data.access_token;
      ITEM_ID = tokenResponse.data.item_id;
      if (PLAID_PRODUCTS.includes('transfer')) {
        TRANSFER_ID = await authorizeAndCreateTransfer(ACCESS_TOKEN);
      }
      response.json({
        access_token: ACCESS_TOKEN,
        item_id: ITEM_ID,
        error: null,
      });
    })
    .catch(next);
});

I have the quickstart server running, my question is, how do I then make the call to the server to exchange the public token for the access token? or in other words, how do I make a post call, containing the public token to the server to receive the access token



Solution 1:[1]

Response from the Plaid Android team:

So in our Android quickstart sample on GitHub, we already have a Retrofit API set up to retrieve the link_token.

What you would want to do is to add something like

  @POST("/api/get_transactions")
  fun getTransactions(publicToken: PublicToken): Single<Transactions>

data class PublicToken(@SerializedName("public_token") publicToken: String)

data class Transactions( @SerializedName("transactions") val transactions: List<Transaction>
)

data class Transaction( @SerializedName("amount") val amount: Float, 
@SerializedName("category") val category: String, 
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex