Triggering a webhook workflow from a retool app?

Wondering if this is possible or I'm doing something wrong?
My use case is to have a central handler for some backend processing when some events in the retool apps occur.
Rather than sweep those changes hourly with a cron job I'd like to run it when it happens, but triggering it from the browser using a run script action with the javascript fetch() command doesn't seem to work.

eg If I run this from the console or a script action it triggers the workflow (I can see it is in the run history) but never receives any data, I'm guessing it may be related to cors but not sure. The response object in each case is always "empty" with a status of zero because the "no-cors" wipes all that out and it won't run without it.

fetch('https://api.retool.com/v1/workflows/xxxxx/startTrigger?workflowApiKey=xxxxx', {
    method: 'POST',
    mode:'no-cors',
    headers: {
        'Content-Type': 'text/plain'
    },
    body: JSON.stringify({
        'action': 'test'
    })
});

or

fetch('https://api.retool.com/v1/workflows/xxxxx/startTrigger?workflowApiKey=xxxxx', {
    method: 'POST',
    mode:'no-cors',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'action': 'test'
    })
});

Logs show this when I test it from within the workflow app with a dummy JSON object:

[log] {
value: { action: 'inline' },
data: { action: 'inline' },
metadata: null,
error: undefined
}

And this when I run that javascript:

[log] { value: {}, metadata: null, data: {}, error: undefined }

Feature request on top of this from me would be a Retool event response to be "Trigger workflow" :-).

1 Like

Hey @dcartlidge!

Can you try running the workflow using a REST query? I'm wondering if using workflowQuery.trigger({additionalScope: {body}}) might work in your script or JS query instead of a direct call to fetch.

Also noted on the feature request @jonathanbredo! It's one of the things on the dev's todo list. I've added your input internally and we'll pass along updates here :slightly_smiling_face:

2 Likes

Excellent, using a RESTQuery works, thanks!