A little help with a script to trigger a webhook

This could potentially help me avoid the need of creating a ton of views and properly work with Zapier.

I’m creating a script that sends data to Zapier that then posts to various social media apps.

I’m facing an issue when including fields that are attachments (images).

Any recommendations on how to handle this?

Example of what I’m working with:

let config = input.config();

await fetch(url + "&instagramCopy=" + encodeURI(config.instagramCopy) + "&twitterCopy=" + encodeURI(config.twitterCopy) + "&facebookCopy=" + encodeURI(config.facebookCopy) + "&facebookMedia=" + encodeURI(config.facebookMedia));```

It looks like I can get the URL of the file by using a formula like so

Now the question is how to do it with the script so that I don’t have a bunch of columns for media files’ URL only to take that and add it to the script.

Get the cell value of the attachment field. It contains the url of the file. The format is documented here.

1 Like

So I’ve managed to get this working but have run into a new issue.

When the copy I’m injecting to the webhook contains a hashtag it doesn’t work.

Anybody how to bypass this?

My current code :point_down:

let url = "https://hooks.zapier.com/hooks/catch/xxxxxx/xxxxx/?";
let config = input.config();
let files = config.mediaFiles.split("https").map(x => { return "https"+x }).slice(1)

await fetch(`${url}&instagramCopy=${encodeURI(config.instagramCopy)}&twitterCopy=${encodeURI(config.twitterCopy)}&facebookCopy=${encodeURI(config.facebookCopy)}&pinterestTitle=${encodeURI(config.pinterestTitle)}&pinterestCopy=${encodeURI(config.pinterestCopy)}&facebookMedia=${files[0]}&instagramMedia=${files[1]}&pinterestMedia=${files[2]}`);

Try using encodeURIComponent instead of encodeURI.

1 Like

That worked! Thank you so much :blush: