How to run loop on API response that has a custom datatype?

Hi everyone,

I need help to setup a workflow. I’m getting a response from external API - List of customers.
Response Structure is similar to this-
… so on

I’m showing this response in RG as a table. Now, the user is selecting some of the rows which I’m storing in a custom state.

I need to use this data from a custom state for a POST API call. This POST API only takes one input at a time so I need to make multiple API calls - one for each entry in my custom state list.

How do I set it up? I tried backend workflow but it takes only basic data types as input. Not with the custom data type of my API call response.

Thanks for the help.

EDIT: I edited this post to clarify the problem in a better way.

All of the fields you’ve listed are of type “text”, so you shouldn’t run into any issues using a backend workflow. Best practice generally speaking is to create a recursive workflow, but given that your objects are quite small (and I’m guessing you won’t be sending more than 3-4 API calls) you could probably get away with just scheduling the API workflow on a list.

1 Like

But how should I do that? I mean that how do I pass the value of this custom state data to the api workflow. The api workflow input parameter can’t have the data type of this custom state. That’s where I’m stuck.

Haha replied to you on Reddit also but here is it again:

Save it in the db. Use it in the backend workflow and discard the data towards the end of the backend workflow if you don’t want the data to live in the system

If you’re making one call at a time, instead of trying to add the custom state’s type, just add three parameters of type text to your backend workflow.

API Params:

Id: text
Name: text
Email: text

Rather than just setting one parameter for the whole custom state, break it down into the text fields. This same logic can be applied to any API call, and means you won’t need to save anything to db, which in turn means you don’t need to create datatypes you don’t need.

Got the first part. How should I break the API call into three parts?

So when you first initialised your API call, it would’ve given you the option to define the type of each field. In your case I’m guessing they’re all just text fields due to their nature.

This means you can create the 3 parameters as I mentioned above, then the syntax will be:

Id: This customer’s id
Name: This customer’s name
Email: This customer’s email

You can never pass custom api response types as backend params, but if you break down the call like that it works just fine.

1 Like

Sorry I meant how should I pass these parameters separate to the API workflow.

But I guess that I can choose -Schedule API Workflow action from workflow and in each input field I pass value as - custom-state’s each item id, custom state’s each item Name and so on?

If you don’t mind giving me access I can for this for you quickly.

But my suggestion would be to schedule the api workflow on a list (the list being your list of customers).

When scheduling on a list, you define the list at the top, then in each of the parameters you can refer to “this customer”, which means every time that scheduled workflow runs, it will dynamically pull the data for the relevant customer.

1 Like

I think I got it. Let me give it a try. I’ll mark as a solution if I don’t have any other query. Thanks a ton.

No problem, let me know if you need more help :smiling_face:

1 Like

Hi @ed19 ,

Thanks for the help earlier. That API workflow worked for me. Now I’m stuck on the next step. So while running that API workflow on loop, some API calls are getting responses as failed with a reason and I need to catch those responses to show it to the user.

Any idea how can I capture these responses and how can I store them in a custom state so that I can show them to the users?

You’re most welcome!

Could you send me a screenshot of the exact error?

I’m calling an Update API of QuickBooks with this recurring workflow. When the update is not possible due to a valid reason, Quickbook send me a 400 error code and the reason. I want to catch the IDs associated with these error codes.

Ah ok, if it’s in the API connector it’s simple enough. There’s a checkbox at the bottom to include errors in the response, but be warned this might break some of your workflows as it essentially sets up a new call (sometimes worth setting up a duplicate call and building workflows in parralel so you have something to reference). The same goes for including headers, useful but can break workflows, so it’s almost worth just checking them from the off if you’re unsure whether you’ll need them.

That I’m getting it. My question is how to capture those ids with this error while running the backend WF API on loop. This is in continuation to the first problem where I’m passing each id data to the API.

I was thinking if I could keep saving those ids in a list (with condition when external api returns error). But there’s no option in Backend WF to access any custom state.

Bear with me, going to try something out that I think may work.

I have found a fun fix for this, but I am still figuring it out a bit (at the moment only works for 2 runs). It will quite genuinely be useful for me too if I can get this to work so will keep trying :slight_smile:

In the meantime, if you’re desperate for a fix you could always just save the responses to a temporary db item and run it that way.

1 Like