How to do back-to-back API calls that depend on data from the previous API call

Really hoping this isn’t going to be a blocker for using

I have a severely outdated client running on Magento 1. I am connecting to Magento 1’s API which involves first making a call to the “login” endpoint, retrieving a “sessionId” and then you can make any subsequent API call that you wish. For my example the next call I’ll be making is to the “lowChatGPTFieldValuesItems” endpoint.

The sessionId from Magento is valid for 1 hour. Since this is an internal application I’m building, I don’t honestly care much even if the login endpoint is called on every page load if it needs to be. All I need, is to get that sessionId so that I can make subsequent calls.

Does anybody know of an acceptable way to approach this?

Here are my API endpoints for the example:

I’ve then tried to create two elements on the page. One, is a hidden text element that loads the sessionId on page load from the API. This is working!

I also created a repeating group element to load the collection of items from the subsequent “lowChatGPTFieldValuesItems” endpoint. When I define the Datasource for this RG element, it wants me to select the API provider and for me to provide a static or dynamic value for the “sessionId”. I’ve tried retrieving the loaded text value from the “sessionId” element on the page. However, it doesn’t appear to allow me to do that.

It will however let me retrieve the “value” from a custom state on that hidden Text element. So I created a custom state. Now I just am trying to figure out how I can update that custom state with the “sessionId” from the “login” API endpoint.

But I honestly don’t know how to do that. My first thought was a backend workflow or an on-page-load event that calls the login API and sets the custom state. But in both the backend workflow and on-page-load event I didn’t see my custom plugin as an option to call. I’m not even sure I’m on the right path…

Please, anybody have ideas?

The login API wouldn’t show as a workflow step because it is set to “use as Data”. Instead you could use the login API as a data source on a workflow step “set custom state”.

You mention the custom state is on a hidden element, do you mean Visible is set to off? Idk if this would cause an issue, if it does, set the custom state on something else, like the page.

Setting the “Login” endpoint to “Use as → Action” does the trick! I’m going to look into more what the difference is between setting this as “Action” vs. “Data”

Now I am able to select the “Login” API call from my “on page load” workflow

And take the “sessionId” from the response of that API call and save it to a custom state on the text element (sessionId) that is hidden on the page.

Now when I go to load my repeating group that is using a data source based on making the secondary call to the “lowChatGPTFieldValueItems” endpoint, I am now able to feed it the “sessionId” from the custom state on the sessionId element.

And my repeating group loads, finally! Without issue!

You are my hero! Thank you so much for your reply. I hope this post helps others with the same issue.

1 Like