Session 8 / 15๐Ÿ”Žืขื‘

How to work with the challenges

The challenges here are harder than the practice tasks, and are meant for those who finished and want to go deeper. Try on your own for at least 20 minutes before opening the hints, and the solution only after that. There is no single right solution: if your scenario meets the requirements, it is right.

Broken scenario โ€” find the bug

This is what real work looks like: something broke, and all you have is the History. Read the error, and pick the right fix.

Advanced: Round-robin between agents

๐Ÿ”ฅ Advancedโฑ๏ธ ~40 min

๐ŸŽฌ The scenario

Split new leads between 3 agents in turns.

๐ŸŽฏ The requirements

  1. A counter in a data store.
  2. Pick an agent by the counter.
  3. Update the counter.

๐ŸŽฏ The desired result โ€” how the scenario should look and work

Click Run once and then each module: you will see its settings, and on the last module โ€” the output you should get.

๐Ÿ“ค Example of the final output
{
  "i": 4,
  "owner": "Michal"
}

๐ŸŽฌ Stuck? To the guided solution with a click simulation โ†’

๐Ÿ’ก Hints (try without them first)
  • Tools โ†’ Increment function returns a rising number (reset by conditions you choose).
  • get(agents; (i mod 3) + 1).

Tools โ†’ Increment function (Reset: Never) โ†’ Set variable owner = get(split("Michal,Ron,Shira"; ","); (1.i - 1) mod 3 + 1). The Increment function keeps the counter itself โ€” without a data store!

๐ŸŽฌ The guided solution โ€” a click simulation

๐Ÿ“ธ The illustrated guide โ€” step by step, click by click

For every step: a screenshot of the (simulated) Make editor with the click spot marked, and below it exactly what to click and what to type. You can work from here next to an open Make window.

  1. 1
    A counter that never resets
    Tools โ†’ Increment function with Reset: Never.
    Marked screenshot โ€” step 1: A counter that never resets
    ๐Ÿ“ธ Step 1.1 โ€” the red ring marks where to click
    Marked screenshot โ€” step 1: A counter that never resets
    ๐Ÿ“ธ Step 1.2 โ€” the red ring marks where to click
    1. In the left menu click Scenarios โ†’ + Create a new scenario.
    2. Click the scenario name at the top left (New scenario) and type: C08 - Round-robin.
    3. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    4. In the search box type Webhooks and click the Webhooks app.
    5. In the list of actions choose Custom webhook.
    6. In the Webhook field type: new-lead
    7. Click OK (or Save) to close the module window.
    8. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    9. In the search box type Tools and click the Tools app.
    10. In the list of actions choose Increment function.
    11. In the Reset a value field type: Never
    12. Click OK (or Save) to close the module window.
  2. 2
    Pick an agent by the counter
    (i โˆ’ 1) mod 3 + 1 returns 1, 2, 3, 1, 2โ€ฆ
    Marked screenshot โ€” step 2: Pick an agent by the counter
    ๐Ÿ“ธ Step 2 โ€” the red ring marks where to click
    1. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    2. In the search box type Tools and click the Tools app.
    3. In the list of actions choose Set variable.
    4. In the Variable name field type: owner
    5. In the Variable value field map (drag from the panel or type): {{get(split("Michal,Ron,Shira"; ","); (2.i - 1) % 3 + 1)}}
    6. Click OK (or Save) to close the module window.
  3. 3
    Save in the CRM
    Insert with owner.
    Marked screenshot โ€” step 3: Save in the CRM
    ๐Ÿ“ธ Step 3 โ€” the red ring marks where to click
    1. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    2. In the search box type PostgreSQL and click the PostgreSQL app.
    3. In the list of actions choose Insert a row.
    4. In the Table field type: deals
    5. In the owner field map (drag from the panel or type): {{3.owner}}
    6. In the email field map (drag from the panel or type): {{1.email}}
    7. Click OK (or Save) to close the module window.
  4. 4
    Test: 4 leads
    Four runs โ†’ Michal, Ron, Shira, Michal.
    Marked screenshot โ€” step 4: Test: 4 leads
    ๐Ÿ“ธ Step 4 โ€” the red ring marks where to click
    1. Click โ–ถ Run once at the bottom left.
    2. When the run ends, bubbles with numbers appear above the modules. Click the bubble of the last module and check the Output.
    3. The output should look roughly like this:
      {
       "i": 4,
       "owner": "Michal"
      }

Experts: Stage history

๐Ÿ”ฅ๐Ÿ”ฅ Expertsโฑ๏ธ ~50 min

๐ŸŽฌ The scenario

Save every stage change in a deal_events table.

๐ŸŽฏ The requirements

  1. An events table.
  2. Record on every update.
  3. An average time-in-stage report.

๐ŸŽฏ The desired result โ€” how the scenario should look and work

Click Run once and then each module: you will see its settings, and on the last module โ€” the output you should get.

๐Ÿ“ค Example of the final output
{
  "rows": [
    {
      "to_stage": "proposal",
      "avg": "3 days 04:00"
    }
  ]
}

๐ŸŽฌ Stuck? To the guided solution with a click simulation โ†’

๐Ÿ’ก Hints (try without them first)
  • A trigger in Postgres or recording from Make on every UPDATE.
  • Window functions (lead) for computing the duration.

A table deal_events(deal_id, from_stage, to_stage, at). In the update API: UPDATE โ€ฆ RETURNING the old one? Simpler: SELECT the stage before, UPDATE, INSERT an event. Report: avg(next_at - at) with lead(at) over (partition by deal_id order by at).

๐ŸŽฌ The guided solution โ€” a click simulation

๐Ÿ“ธ The illustrated guide โ€” step by step, click by click

For every step: a screenshot of the (simulated) Make editor with the click spot marked, and below it exactly what to click and what to type. You can work from here next to an open Make window.

  1. 1
    A deal_events table
    deal_id, from_stage, to_stage, at.
    Marked screenshot โ€” step 1: A deal_events table
    ๐Ÿ“ธ Step 1 โ€” the red ring marks where to click
    1. Open supabase.com/dashboard in your browser (the โ€œSQL editorโ€ screen).
    2. On the screen you will see: create table deal_events (id bigserial primary key, deal_id bigint, from_stage text, to_stage text, at timestamptz default now());
    3. Click the Run button.
  2. 2
    Read the current stage
    In the update API: SELECT stage before the update.
    Marked screenshot โ€” step 2: Read the current stage
    ๐Ÿ“ธ Step 2.1 โ€” the red ring marks where to click
    Marked screenshot โ€” step 2: Read the current stage
    ๐Ÿ“ธ Step 2.2 โ€” the red ring marks where to click
    1. In the left menu click Scenarios โ†’ + Create a new scenario.
    2. Click the scenario name at the top left (New scenario) and type: C08 - Stage history.
    3. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    4. In the search box type Webhooks and click the Webhooks app.
    5. In the list of actions choose Custom webhook.
    6. In the Webhook field type: update-deal
    7. Click OK (or Save) to close the module window.
    8. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    9. In the search box type PostgreSQL and click the PostgreSQL app.
    10. In the list of actions choose Execute a query.
    11. In the Query field type: select stage from deals where id = $1
    12. In the Parameters field map (drag from the panel or type): {{1.id}}
    13. Click OK (or Save) to close the module window.
  3. 3
    Update + record an event
    UPDATE followed by an INSERT into deal_events.
    Marked screenshot โ€” step 3: Update + record an event
    ๐Ÿ“ธ Step 3.1 โ€” the red ring marks where to click
    Marked screenshot โ€” step 3: Update + record an event
    ๐Ÿ“ธ Step 3.2 โ€” the red ring marks where to click
    1. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    2. In the search box type PostgreSQL and click the PostgreSQL app.
    3. In the list of actions choose Update a row.
    4. In the Table field type: deals
    5. In the stage field map (drag from the panel or type): {{1.stage}}
    6. Click OK (or Save) to close the module window.
    7. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    8. In the search box type PostgreSQL and click the PostgreSQL app.
    9. In the list of actions choose Insert a row.
    10. In the Table field type: deal_events
    11. In the deal_id field map (drag from the panel or type): {{1.id}}
    12. In the from_stage field map (drag from the panel or type): {{2.stage}}
    13. In the to_stage field map (drag from the panel or type): {{1.stage}}
    14. Click OK (or Save) to close the module window.
  4. 4
    Average time-in-stage report
    A query with lead(at) over (partition by deal_id).
    Marked screenshot โ€” step 4: Average time-in-stage report
    ๐Ÿ“ธ Step 4.1 โ€” the red ring marks where to click
    Marked screenshot โ€” step 4: Average time-in-stage report
    ๐Ÿ“ธ Step 4.2 โ€” the red ring marks where to click
    1. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    2. In the search box type PostgreSQL and click the PostgreSQL app.
    3. In the list of actions choose Execute a query.
    4. In the Query field type: select to_stage, avg(next_at - at) from (select *, lead(at) over (partition by deal_id order by at) next_at from deal_events) x group by 1
    5. Click OK (or Save) to close the module window.
    6. Click โ–ถ Run once at the bottom left.
    7. When the run ends, bubbles with numbers appear above the modules. Click the bubble of the last module and check the Output.
    8. The output should look roughly like this:
      {
       "rows": [
        {
         "to_stage": "proposal",
         "avg": "3 days 04:00"
        }
       ]
      }

Boss challenge: RPC in Supabase

๐Ÿ‘‘ Boss challengeโฑ๏ธ ~60 min

๐ŸŽฌ The scenario

Move the upsert logic into a function in the database, and Make only calls it.

๐ŸŽฏ The requirements

  1. A SQL function upsert_deal.
  2. A call from Make through REST (rpc).
  3. A secure key.

๐ŸŽฏ The desired result โ€” how the scenario should look and work

Click Run once and then each module: you will see its settings, and on the last module โ€” the output you should get.

๐Ÿ“ค Example of the final output
{
  "data": 57
}

๐ŸŽฌ Stuck? To the guided solution with a click simulation โ†’

๐Ÿ’ก Hints (try without them first)
  • insert โ€ฆ on conflict (email) do update requires a unique constraint on email.
  • POST /rest/v1/rpc/upsert_deal.

create unique index on deals(email); create function upsert_deal(p jsonb) returns bigint โ€ฆ on conflict โ€ฆ returning id. In Make: HTTP POST https://xyz.supabase.co/rest/v1/rpc/upsert_deal with apikey and Authorization headers from Keychain. One module instead of three.

๐ŸŽฌ The guided solution โ€” a click simulation

๐Ÿ“ธ The illustrated guide โ€” step by step, click by click

For every step: a screenshot of the (simulated) Make editor with the click spot marked, and below it exactly what to click and what to type. You can work from here next to an open Make window.

  1. 1
    A unique index and a function in the database
    upsert_deal(p jsonb) with on conflict (email).
    Marked screenshot โ€” step 1: A unique index and a function in the database
    ๐Ÿ“ธ Step 1 โ€” the red ring marks where to click
    1. Open supabase.com/dashboard in your browser (the โ€œSQL editorโ€ screen).
    2. On the screen you will see: create unique index on deals(email); ยท create function upsert_deal(p jsonb) returns bigint โ€ฆ on conflict (email) do update โ€ฆ returning id;
    3. Click the Run button.
  2. 2
    A key in Keychain
    Keychain โ†’ the Supabase API key, not inside the module.
    Marked screenshot โ€” step 2: A key in Keychain
    ๐Ÿ“ธ Step 2 โ€” the red ring marks where to click
    1. Open eu2.make.com/keychains in your browser (the โ€œKeysโ€ screen).
    2. On the screen you will see: Add key ยท Type: API key ยท Name: supabase-service
    3. Click the Save button.
  3. 3
    Call the RPC
    HTTP POST to /rest/v1/rpc/upsert_deal.
    Marked screenshot โ€” step 3: Call the RPC
    ๐Ÿ“ธ Step 3.1 โ€” the red ring marks where to click
    Marked screenshot โ€” step 3: Call the RPC
    ๐Ÿ“ธ Step 3.2 โ€” the red ring marks where to click
    1. In the left menu click Scenarios โ†’ + Create a new scenario.
    2. Click the scenario name at the top left (New scenario) and type: C08 - RPC.
    3. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    4. In the search box type Webhooks and click the Webhooks app.
    5. In the list of actions choose Custom webhook.
    6. In the Webhook field type: deal
    7. Click OK (or Save) to close the module window.
    8. Click the + (the big circle in the middle, or the half-circle to the right of the last module).
    9. In the search box type HTTP and click the HTTP app.
    10. In the list of actions choose Make a request.
    11. In the URL field type: https://xyz.supabase.co/rest/v1/rpc/upsert_deal
    12. In the Method field choose: POST
    13. In the Headers field type: apikey + Authorization (Keychain)
    14. In the Body field map (drag from the panel or type): {"p": {{toJSON(1)}}}
    15. Click OK (or Save) to close the module window.
  4. 4
    Run
    One module instead of three โ€” the id comes back.
    Marked screenshot โ€” step 4: Run
    ๐Ÿ“ธ Step 4 โ€” the red ring marks where to click
    1. Click โ–ถ Run once at the bottom left.
    2. When the run ends, bubbles with numbers appear above the modules. Click the bubble of the last module and check the Output.
    3. The output should look roughly like this:
      {
       "data": 57
      }