Making a module from a workflow query

I made a Workflow to log user activity in my apps. I can trigger it from my app and pass the JSON parameters that contain the values I want to log. In short, it works as designed (and was super easy to make.)

Now, I want to integrate this workflow into 10 different Retool applications. It would help if the resource query could be copied between apps or made into a module so I don't have to configure all the fiddly parameters each time.

It isn't that big of a deal to create the resource query by hand for each app, but it makes using a workflow for this solution more effort than modularizing the logging SQL query itself and placing it in each app. Making something more effort is hard to explain to my friends, and "workflows are cool!" isn't persuasive enough for them.

I started using a workflow instead of the "local to the app" SQL query because I'm constantly looking for ways to reduce the number of times I go to the app's DB. My performance scores are laaaaaaaaame.

Does anyone else have a similar need for reusing workflow queries between apps?

Hi Andrew,

Great question! I just did some testing out and think I have a viable solution for you. You can setup the workflow's webhook url as a Rest API resource and then reference it as a resource in new entry in the Query Library. Here is what I did for my query. If you use {{ }} values then you will create variables that the query will want to collect values for later:

Make sure that query is saved and shared, so we can then import it into our app.

Select the query we just created and you will see fields that are based off the two {{ }} variables that I setup earlier when I created the query in the library.

Now all I need to do is pass in the values to those variable and they will get set in the query in the fields that I defined them in earlier.

Hopefully that was what you were looking for and will save you sometime when you build in the future! Let me know if that works.

Hi @awilly, just wanted to follow up with you and see if this helped with your workflow.

Hey @Taylor_M !

I apologize for not getting back to you. Your idea looks good, and I'm trying it now. I'll be back to mark solution once I've got it working!

1 Like

I am having trouble getting the API resource up and working. Two important details: I am not a developer, and, we're self-hosted.

The latest error is below. I get it in both Retool and in Postman. I had to disable SSL verification to get this far.

error:"{"success":false,"message":"Authentication failure. Incorrect private key for X-API-Key header."}"

It looks like your example requires an API key, but not a private key. Are those concepts distinct? My error is the same if I send the API key or not.

This webhook does work as a Workflow node within an app.

If there is a step-by-step guide for integrating with the workflow webhook, I couldn't find it.

Hey @awilly!

Great question! And no problem! I could have been a bit more explicit there.

It is specifically the API key that is tied to the workflow that is needed. If you go in your workflow and navigate to the triggers in the left menu and then click on your webhook you should see the below with an Api Key. That is what you will need to pass in your headers as X-Workflow-Api-Key.

You do not need to explicitly do this when you pick the Workflow resource from the app because that part is "abstracted" by Retool and done for you. To create a query "template" though in the Query Library the workflows resources are not directly supported so we couldn't use that. Instead I had to create a basic Rest API resource that pointed to the webhook in its place and therefore needs that header added so then we could create the reusable query off of that.

Let me know if that gets it working!

1 Like

Thank you for your continued help! I snagged the API key as described and tried it out with Query Library test and in Postman. In the query library, I both explicitly defined the API key in the header as part of the query, or left it to inherit from the resource configuration.

Here is the resource configuration example:

Here is the Postman example:

In the Postman example, you are currently adding the key as a parameter. Add it to the Headers instead and see if that goes through successfully.

Were you getting a similar error in Retool?

1 Like

Thanks for the Postman tip! Switching to headers did the trick.

Yes, I had been getting the same error in Retool with the config above. But now, it's working great. I assume my testing was inconsistent.

Now that the Rest API resource is working (thanks again) I'll try logging with the query library and get back to you.

Works great. Thank you for your help!

1 Like