Running Scenario via api using Apps Script

Hi, I am using Google Apps Script to set up a trigger which should runs the scenario in theory. However, when I run it, I see “502 Bad Gateway” error message on my make.com dashboard. Please check if the credentials format is correct.

https://eu2.make.com/api/v2/1234567/scenarios/7654321/run

is 1234567 = organization id ?
is 7654321 = scenario id ?

Bearer 90649e3ddd3e05f52f8759488653392b

function onFormSubmit(e) {
  const url = 'https://eu2.make.com/api/v2/1234567/scenarios/1234567/run'; // Replace with your Make.com scenario URL
  const options = {
    method: 'post',
    headers: {
      'Authorization': 'Bearer 90649e3ddd3e05f52f8759488653392b', // Your actual Bearer Token
      'contentType': 'application/json'
    },
    muteHttpExceptions: true
  };

  UrlFetchApp.fetch(url, options);
}

function setup() {
  ScriptApp.newTrigger('onFormSubmit')
    .forForm(FormApp.openById('ANjnG3nv8J_G1pO8PDSmYnaU224eeM9QU')) // Your form ID
    .onFormSubmit()
    .create();
}

Please use simple exact format like me with made up numbers. I don’t understand the API doc.

You may want to remove the Bearer token from your post.

I believe you can use a Webhook module for this, without needing to use the API. That way you don’t have to hit the /run endpoint you’re using and can directly hit a webhook instead.

A guide is here: https://www.make.com/en/help/tools/webhooks

1 Like

Thank you but it’s not a real token and for my scenario, webhooks method doesn’t seem to work.

Hello @Aka_H,
As @c0bbler said check their webhooks documentation that’s the way you can understand how webhooks work differently than regular API requests.
If you need to know more in-depth check academy.make.com
Specific link What are Webhooks?
But I recommend you go step by step.
:+1:

I can not put the webhooks before Google forms module, thank you for your response.

It looks like from your screenshot you shoudl connect the webhook to the google form. Are you saying when you try to connect it you get this error? Typically webhooks are a trigger, I use them in many workflows.