Unable to get URL from google sheets into a Post_Request

STEP: 1 Trigger

I’m using a google sheets trigger - “New Updates (Instant) from Google Sheets”, where an URL appears periodically. The result of the trigger shows the URL.

STEP: 2 Post_request

However using the resulting variable {{steps.trigger.event.currentValues.values[2][0]}} from the trigger in an extractor in the next step where I’ve used a post request gives an error.

If I hardcode the URL into the extractor it works.

If the data is only appearing periodically, then you’ll need to exit the workflow early or provide static values in case the URL isn’t present in the payload.

You can use a Node.js code step to exit a workflow early, or you can use the Filter actions to exit a workflow early based on missing data.

The data appears without a error, everytime the google sheet is updated with a new URL it shows in the trigger result, screen shot attached.

However when I use that variable in the post_request it throws up an error.

For example (in the screenshot): replacing “url”: “{{steps.trigger.event.currentValues.values[2][0]}}”, with the URL itself works “url”: “askgamblers.com/online-casinos/reviews/chipstars-casino”,

So I’m not sure why the variable for the URL shows in the trigger doesn’t work in the post_request.

Hi @merckom

Have you tried copying and pasting your example payload into a JSON formatting tool?

It might help tell you exactly where the issue lies, I suspect your "extractor" value is escaping the quotes somehow.

Here’s an example of a JSON formatting tool: https://jsonformatter.curiousconcept.com/

Thanks, I ran it through the JSON formatting tool, it came out as valid, this is the payload I’m using.

{
   "url":"{{steps.trigger.event.currentValues.values[2][0]}}",
   "method":"GET",
   "retryNum":1,
   "geo":"us",
   "extractor":"// define function which accepts body and cheerio as args\nfunction extract(input, cheerio) {\n    // return object with extracted values              \n    let $ = cheerio.load(input);\n  \n    let items = [];\n    $('.review-details__title').map(function(){\n              let infoTr = $(this).next();\n            items.push([\n              infoTr.text().trim()\n            ]);\n         });\n  \n  return { items };\n}"
}

For some reason it’s not resolving or picking up the URL from the variable even though it shows in the trigger result.

I believe the issue you might be having is the evaluation isn’t happening because it’s wrapped in strings.

Have you tried wrapping the entire payload with the JS evaluation handlebars like so?

{{
  {
     "url": steps.trigger.event.currentValues.values[2][0],
     "method":"GET",
     "retryNum":1,
     "geo":"us",
     "extractor":"// define function which accepts body and cheerio as args\nfunction extract(input, cheerio) {\n    // return object with extracted values              \n    let $ = cheerio.load(input);\n  \n    let items = [];\n    $('.review-details__title').map(function(){\n              let infoTr = $(this).next();\n            items.push([\n              infoTr.text().trim()\n            ]);\n         });\n  \n  return { items };\n}"
  }
}}

Hi @pierce, thank you very much, that seems to have fixed the problem.

1 Like