Best practice for including user or item IDs that need to be looked up, in a JSON module

Hi

I have created a scenario that will take an Evernote note and create a Motion task from it.

Motion doesn’t have an integration so I have had to a create JSON module followed by an HTTP module to call the Motion API and create a task. It works!

If this was a “proper” integration however, when I linked Evernote to Motion, it would let my choose the user and workspace I want the new task created with from a drop down list.

What’s the best practice to emulate this? Right now I just use another tool to call the Motion API to return a list of user and workspace IDs, then I copy and paste that ID string into the JSON module. As I say, it works but is clunky and hard coded.

Is there a more elegant way of doing this rather than hard coding it?

Thanks

Stuart

Hi @Stuart_Mingay,

One option here is to create a custom app and you use what’s called RPCs to get lists of options that you can select from before running the function to create a task.

To do this without creating a custom app, you would typically use the service’s API to create a list of X (which typically generates a bunch of bundles),
Aggregator module to aggregate list of X (which creates an array),
Then use map() function to create a “sub-array”,
Then use get() to get a specific element from the new sub-array.

Let’s say you query Motion for a list of Workspaces and the result is:
Bundle 1:
name: Workspace 1
id: 1

Bundle 2:
name: Workspace 2
id: 2

Bundle 3:
name: Workspace 3
id: 3

Then the Aggregator would combine all these bundles into a single array of collections. It looks very similar except everything is contained within an array, which can be mapped. Call this the aggregator_array.

To use map, you’d use map(aggregator_array;id;name;Workspace 2)
This will create a new array of all the ids [1, 2, 3], but would apply a filter to include only those ids where the name is Workspace 2. In that case the return wouldn’t only be [2].

Then, use the get() function (which will get the first item in the array, which in this case is the only item in the array) to return 2. Now you have the id of the workspace for your module that creates a Motion task.

I hope this makes sense!

2 Likes

Thanks for the reply! I’ll spend a bit of time going through what you’ve written and work out a reply!

Thanks

Stuart