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?
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.
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.
Hello @zezutom , how is the project going so far ? I am also looking forward to create scenario dynamically so this feature would be awesome
hi @Albanmana ,
Glad you asked! Check my post here and please let me know your thoughts.
Thank you @zezutom , well explained and practical
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?
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?
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.
@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
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:
The Dynamic Approach
/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./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
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.
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.
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:
/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.body.response.blueprint
object as the source.body.response.schedule
object/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.
Had to use the following syntax for the json in the final āMake an API Callā:
And here you can see the value as it should be of 36. JSON string: