Using a response handler to capture a payload/response and use that data inside my application/API connector

Hey!

I have an API set up that uses a link token → public token → account token

Step 1) capture link token through the API connector, store link token in db
Step 2) use a js script to pass in my link token to get public token
Step 3) use chrome web tools to find the public token in the network tab
Step 4) pass public token for account token

Very easy to set up, but the issue is that in order to get the account token, I have to consult the chrome web tools, inspect the network events, find the right file, open that up, trudge through nested responses to ultimately find my public token.

Very cool - except I want to automate this, obviously.

What is the best way to capture a response handler/response info from the network tab?

Thanks!

2 Likes

Welcome to bubble. So much is usually hard is so easy. So much that’s so easy is sometimes so hard. You’ll want to use a plugin to extract the Json most likely. Then feed it into the RG as a list of items

Possible to share your API doc? And the JS you are using and how you use it.

1 Like
<button id="open-link-button">Start linking</button>
<script src="https://cdn.merge.dev/initialize.js"></script>
<script type="text/javascript">
  const button = document.getElementById("open-link-button");
  button.disabled = true;

  function onSuccess(public_token) {
    // Send public_token to server (Step 3)
  };

  MergeLink.initialize({
    linkToken: "ADD_GENERATED_LINK_TOKEN", // Replace ADD_GENERATED_LINK_TOKEN with the token retrieved from your backend (Step 1)
    onSuccess: (public_token) => (onSuccess(public_token)),
    onReady: () => (button.disabled = false),
  });

  button.addEventListener("click", function () {
    MergeLink.openLink();
  });
</script>

This is the script that I’m using to get the public token.

merge.dev is the tool I’m trying to ultimately use :slight_smile:

And where do you use this script? In an HTML element? With Toolbox? In a plugin?

Toolbox, yes.

I don’t think this is going to work for me :frowning:

This is the data I’m trying to bring back into Bubble. Any plugin makers, perhaps?

Bump!

Personnally, I prefer to create a plugin. But Ithink it’s possible with toolbox.
In the onsuccess part, this is the moment to use the bubble function and the trigger event and publish data.
Look a short example here:
Toolbox plugin - collection of utility elements (#Javascript to Bubble)

1 Like

Amazing. I’ve been using toolbox for quite some time and had no idea about the js - > bubble element. This solved my issue perfectly.

2 Likes

Forgive digging up this old thread - can you help me understand what you mean by “in the onsuccess part, this is the moment to use the bubble function”??

So, if I am using bubble_fn_thesuffix, where and what should I be including?

Would it be bubble_fn_thesuffix(public_token)?

Does that need to live in a particular spot in the code Cameron shared above?

Much appreciated!