How to put together blueprints to run a scenario with API

Hey guys,

Has anyone ever used the API to create scenarios? How do I go about creating the blueprint for the scenario as well as adding the connections and all that?

@zezutom might have some input here.

1 Like

Hi guys,
Yup, I will soon publish a repository with Java / Kotlin / JS client for the Make API. It will allow to create scenarios, fetch details about scenario modules and also update modules within a scenario.

2 Likes

Hello @zezutom , how is the project going so far ? I am also looking forward to create scenario dynamically so this feature would be awesome

2 Likes

hi @Albanmana ,
Glad you asked! Check my post here and please let me know your thoughts. :slight_smile:

2 Likes

Thank you @zezutom , well explained and practical :ok_hand:

Unfortunately I am not really familiar with the coding language you used in the video, and generating a blueprint then importing it might be fastidious in the long run.

What I was looking for is a way to clone scenarios via an HTTP Request, I already figured out how to do it (attachement), but I am having trouble changing the connexions (like webhooks). Any ideas on how to do it ?



Thank you for your feedback @Albanmana.

In the demo I copied json manually to keep things nice and simple. But in reality I am already working on a HTTP client that would leverage Makeā€™s API - just like in your example.

You see, the advantage of having an SDK is that it ā€œunderstandsā€ the structure of the scenario. Without this insight, you have to resort to parsing JSON and look for specific properties on your own. Makeā€™s API allows you to upload the entire blueprint, but AFAICS there is no way to update individual modules within the blueprint. Please feel free to prove me wrong, it would be great news to me.

In terms of coding language I used Kotlin. I understand this is a fairly niche language. Would you consider using the SDK if it was coded in JavaScript?

1 Like

Actually you gave me an idea. My HTTP client could use the SDK internally and expose an API that would satisfy your need.

For example, your current use case seems to be ā€œclone a scenario and update some of its modulesā€.

In this case you would use my HTTP client roughly like this (just a pseudo-code):

MakeHttpClient("your api key", "your team id", "your org id")
.cloneBlueprint("blueprint.json")
.withChangedModule("your module id or name", "hook" -> "21. Hook ID")
.sendRequest()

The code above would upload an updated version of your blueprint.

What do you think?

1 Like

I have a scenario that creates new scenarios from a blueprint, but also creates a new Slack webhook, and sets that as the trigger and turns the scenario on.
The biggest issue I ran into was forming the post request for the new scenario using JSON that contained both dyamically updated fields, as well as IML from the original blueprint. If you try to just include the whole blueprint, the interface has a bit of a meltdown because it tries to reference any IML to a module that doesnā€™t exist (or worse, one that does).
My workaround was to import the parts of the blueprint with static IML from Google sheets, and the rest I would update dynamically and then splice them together in the POST request. Kind of a hack I guess, and hard to maintain, but otherwise works reliably.

3 Likes

@MichaelStranks would be very interested to know more details about your solution. Specifically, did you have to escape any special characters to get your POST working?

@zezutom I checked out your Makker GitHub repo, nice work! I do really like your idea for it to expose an endpoint that could modify and post Blueprints, could be powerful. That said, like @Albanmana, I am also not experienced with Kotlin. In addition, having to use and deploy a separate app to form the correct requests from a no-code app is not ideal so Iā€™m conflicted :wink:

Tammy I know the answer is likely no longer relevant but here are two solutions to the problem with the hopes that others might benefit from the information / contribute to improving it:

UPDATE: SEE GREATLY IMPROVED METHOD IN NEXT POST

The Dynamic Approach

  1. Add a ā€œMake an API Callā€ module from the Make app. GET the /v2/scenarios/<scenarioId>/blueprint URL. Note: This source scenarioId could be a template of sorts, or you can make multiple calls to multiple source scenarios to compose in the next step as you suggest.
  2. Convert the response to a JSON string by adding a ā€œTransform to JSONā€ Module and using the body.response.blueprint object as the source.
  3. Add one or more ā€œReplaceā€ modules with the output of the previous step as a source. This will allow you to use a RegEx to modify the contents. You may also want a ā€œCompose a Stringā€ step to combine multiple elements. Based on my testing, there is a requirement for at least one Replace module to escape doublequotes (") with the backslash . So " ā†’ "
  4. Repeat steps 2 and 3 for the body.response.schedule object
  5. Add a ā€œMake an API Callā€ module from the Make app. PATCH the /v2/scenarios/<scenarioId>/blueprint URL. Add a JSON Content-type header and the following to the body:
    {"blueprint":"{{##.convertedBlueprint}}", "scheduling":"{{##.convertedSchedule}}"}

The big caveat with this approach is that while it works for simple flows, especially those that have not been run, Iā€™ve not been able to figure out the correct steps to clean the Blueprint once the flow runs or is more complicated resulting in more special characters and combinations in the Blueprint.

IF ANYONE KNOWS THE CORRECT SEQUENCE OF REPLACE AND REGEX TO USE OR ANOTHER WAY TO DO THIS, Iā€™D BE ENORMOUSLY APPRECIATIVE.

I have a ticket in to Make support about it but theyā€™re really slow to reply. Will update if I hear back.

The Static Approach

  1. Add a ā€œCompose A Stringā€ module. Paste the Blueprint into the text. I have found the easiest way to get a properly escaped Blueprint string is to use my browserā€™s Dev Tools to inspect the call being made when you save a scenario. Then download the RAW version. Another trick here is to avoid Make trying to reference modules in the text, like @MichaelStranks pointed out, I replace all instances of { with | in the string before pasting it.
  2. Add one or more ā€œReplaceā€ modules with the output of the previous step as a source. This will allow you to use a RegEx to modify the contents. You may also want a ā€œCompose a Stringā€ step to combine multiple elements. There is no need to escape special characters with this approach but you do need one Replace step to convert those | characters back to {.
  3. Same as last step of the dynamic approach

Overall, both approaches are not great so if anyone has found better solutions, I think the community would benefit from hearing it!

CCs:
@PraneethG as I see you had a similar issue.
@alex.newpath I see you suggested using the map() function for replacing parts of the JSON however my testing seems to suggest that map() can only handle Arrays and the response from the call to the API is a deeply nested object. It would also require re-composing a very complicated object. Because of these issues Iā€™m not sure if this would work? Admittedly Iā€™m not well practiced using the map() function so if you have some tips for using this approach I think Iā€™d be a big win.

1 Like

map() is absolutely used for arrays only and I am talking about manipulating arrays inside the JSON object or at least extracting parts of it. JSON object is just a set of key/value pairs and yes it can get quite deeply nested but still in the end it is one big collection.

1 Like

Thanks @alex.newpath, appreciate the clarification & info.

I kept working on the original issue of how to compose and upload a blueprint and found a simple and robust solution for most of the problem. Hereā€™s the new approach:

  1. Add a ā€œMake an API Callā€ module from the Make app. GET the /v2/scenarios/<scenarioId>/blueprint URL. Note: This source scenarioId could be a template of sorts, or you can make multiple calls to multiple source scenarios to compose in the next step as @Tammy suggests.
  2. Convert the response to a JSON string by adding a ā€œTransform to JSONā€ Module and using the body.response.blueprint object as the source.
  3. Add one or more ā€œReplaceā€ modules with the output of the previous step as a source. This will allow you to use a RegEx to modify the contents. In most cases, mapping the current value of the thing you want to replace as the match string should allow easy replacing of most things unless they are not unique. I have not found a better way to replace parts of the collection yet, but more on that below
  4. NEW Convert the result of step 3 to a JSON string by adding a ā€œTransform to JSONā€ Module and using the previous step as the source.
  5. Repeat steps 2-4 for the body.response.schedule object
  6. Add a ā€œMake an API Callā€ module from the Make app. PATCH the /v2/scenarios/<scenarioId>/blueprint URL. Add a JSON Content-type header and the following to the body: {"blueprint":"{{##.convertedBlueprint}}", "scheduling":"{{##.convertedSchedule}}"}

I found that this new approach worked consistently even with complicated blueprints. I am not 100% sure but I believe the need to transform the blueprint and schedule to a JSON twice is because they are being passed as part of a JSON that we create in step 6.

A little more info on step 3. As mentioned, Iā€™ve not found a good way to update just one part of a collection without having to incur alot of operations to iterate over everything in the collection and re-compose it. That said, this would be trivial with a bit of code and I believe it can be done with a Custom Make App. If I ever get around to it I will post the details here but I welcome others to give it a go or suggest a smart way!

Hope this helps someone down the road. :robot:

4 Likes

Had to use the following syntax for the json in the final ā€œMake an API Callā€:

Bildschirmfoto 2023-05-03 um 12.18.56

And here you can see the value as it should be of 36. JSON string:
Bildschirmfoto 2023-05-03 um 12.20.02

1 Like