Run a scenario everyday at random time between 8:00 - 12:00

Hello,

I need to make a scenario which runs everyday at random time but in between 8:00 and 12:00
How can i do that in make.com?

Welcome to the Make community!

Yes, that is possible. You’ll only need one module to do that.

You can use the Make app “Make an API Call” to set the next time the scenario is going to run.

Screenshot_2024-01-19_200151

Details of the Make API to “Update scenario” can be found here https://www.make.com/en/api-documentation/scenarios-scenarioId-patch

Before

Screenshot_2024-01-19_200140

1. Make: Make an API Call

Update current scenario’s scheduling using Scenario id variable

Output

Screenshot_2024-01-19_200125

After

Scenario now has a new random time between 08:00 and 11:59

Screenshot_2024-01-19_200136

Screenshot_2024-01-19_200144

Note: You must refresh your browser to see the updated scheduling if you are editing your scenario. Updated changes will not be loaded until you reload the web editor.

Give it a go and let us know if you have any issues!

3 Likes

Thank you, can you please prive me a blueprint?
I cannot recreate this… it doesnt work for me… i think im missing something at the begnining.

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
  "subflows": [
    {
      "flow": [
        {
          "id": 42,
          "module": "make:makeApiCall",
          "version": 1,
          "parameters": { "__IMTCONN__": 113550 },
          "mapper": {
            "url": "/v2/scenarios/{{var.scenario.id}}",
            "body": "{\n \"scheduling\": \"{\\\"time\\\":\\\"{{formatDate(setMinute(setHour(now; 8 + floor(random * 4)); 0 + floor(random * 60)); \"HH:mm\")}}\\\",\\\"type\\\":\\\"daily\\\"}\"\n}",
            "method": "PATCH",
            "headers": [{ "key": "Content-Type", "value": "application/json" }]
          },
          "metadata": {
            "designer": { "x": 2, "y": -481 },
            "restore": {
              "expect": {
                "qs": { "mode": "chose" },
                "method": { "mode": "chose", "label": "PATCH" },
                "headers": { "mode": "chose", "items": [null] }
              },
              "parameters": {
                "__IMTCONN__": {
                  "data": { "scoped": "true", "connection": "make" },
                  "label": "Make API"
                }
              }
            },
            "parameters": [{ "name": "__IMTCONN__", "type": "account:make", "label": "Connection", "required": true }],
            "expect": [
              { "name": "url", "type": "text", "label": "URL", "required": true },
              {
                "name": "method",
                "type": "select",
                "label": "Method",
                "required": true,
                "validate": { "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] }
              },
              {
                "name": "headers",
                "spec": [
                  { "name": "key", "type": "text", "label": "Key" },
                  { "name": "value", "type": "text", "label": "Value" }
                ],
                "type": "array",
                "label": "Headers"
              },
              {
                "name": "qs",
                "spec": [
                  { "name": "key", "type": "text", "label": "Key" },
                  { "name": "value", "type": "text", "label": "Value" }
                ],
                "type": "array",
                "label": "Query String"
              },
              { "name": "body", "type": "any", "label": "Body" }
            ]
          }
        }
      ]
    }
  ],
  "metadata": { "version": 1 }
}

3 Likes

Thank you!

I got 2 questions:

  1. This way - should put this module “Make an API Call” at the end of my Scenario - so it will up update the Shedule Time for the next run yes?

  2. How about when run is for example: at 9:30 - and then Scenario will update next run time to 10:30, it will run again at the same day? I want to run it only once per day.

Okay i think i found solution for my problem. Thank you!

Yes. You can also use “once” (on the next day)

{
  "scheduling": "{\"date\":\"{{setMinute(setHour(addDays(now; 1); 8 + floor(random * 4)); 0 + floor(random * 60))}}\",\"type\":\"once\"}"
}

but if you use this, I think you might also need to set the schedule to “on” as well, using the turn a scenario scheduling on/off module.

Below is the updated module export:-

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
  "subflows": [
    {
      "flow": [
        {
          "id": 42,
          "module": "make:makeApiCall",
          "version": 1,
          "parameters": {
            "__IMTCONN__": 113550
          },
          "mapper": {
            "url": "/v2/scenarios/{{var.scenario.id}}",
            "method": "PATCH",
            "headers": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": "{\n  \"scheduling\": \"{\\\"date\\\":\\\"{{setMinute(setHour(addDays(now; 1); 8 + floor(random * 4)); 0 + floor(random * 60))}}\\\",\\\"type\\\":\\\"once\\\"}\"\n}"
          },
          "metadata": {
            "designer": {
              "x": 2,
              "y": -481
            },
            "restore": {
              "parameters": {
                "__IMTCONN__": {
                  "label": "Make API",
                  "data": {
                    "scoped": "true",
                    "connection": "make"
                  }
                }
              },
              "expect": {
                "method": {
                  "mode": "chose",
                  "label": "PATCH"
                },
                "headers": {
                  "mode": "chose",
                  "items": [null]
                },
                "qs": {
                  "mode": "chose"
                }
              }
            },
            "parameters": [
              {
                "name": "__IMTCONN__",
                "type": "account:make",
                "label": "Connection",
                "required": true
              }
            ],
            "expect": [
              {
                "name": "url",
                "type": "text",
                "label": "URL",
                "required": true
              },
              {
                "name": "method",
                "type": "select",
                "label": "Method",
                "required": true,
                "validate": {
                  "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"]
                }
              },
              {
                "name": "headers",
                "type": "array",
                "label": "Headers",
                "spec": [
                  {
                    "name": "key",
                    "type": "text",
                    "label": "Key"
                  },
                  {
                    "name": "value",
                    "type": "text",
                    "label": "Value"
                  }
                ]
              },
              {
                "name": "qs",
                "type": "array",
                "label": "Query String",
                "spec": [
                  {
                    "name": "key",
                    "type": "text",
                    "label": "Key"
                  },
                  {
                    "name": "value",
                    "type": "text",
                    "label": "Value"
                  }
                ]
              },
              {
                "name": "body",
                "type": "any",
                "label": "Body"
              }
            ]
          }
        }
      ]
    }
  ],
  "metadata": {
    "version": 1
  }
}
2 Likes

Hello there @Kamil_Goraj :blob_wave:

Great to hear that your scenario is working flawlessly!

Do you mind marking one of the suggestions from @samliew in this thread as a solution? This way we keep our community organized and healthy for other users.

Thanks a lot! :pray:

1 Like