Is it possible to pass variables into API Import?
I need an endpoint like so:
https://app.asana.com/api/1.0/tasks/?project=2274838407251433&completed_since=2020-05-10
Where completed_since=
has a value of now()
Is it possible to pass variables into API Import?
I need an endpoint like so:
https://app.asana.com/api/1.0/tasks/?project=2274838407251433&completed_since=2020-05-10
Where completed_since=
has a value of now()
Yes try the API Enrichment feature… you can use curly braces to reference values from data you have at the time
+1 to what @Varun_Goel said. You can use the Date and Time Import
or Add Date and Time
steps to get the date value you’d like to pass in and then use the API Enrichment
step.
Ha… I wasn’t aware of the Date and Time Import option. I settled for something a little more flexible by calling our mySQL database for the following:
SELECT UNIX_TIMESTAMP(CURDATE()) AS TODAY
, UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL- 7 DAY)) AS LASTWEEK
, UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL(1-DAYOFWEEK(CURDATE())) DAY)) AS SUNDAY
, UNIX_TIMESTAMP(DATE_ADD(DATE_ADD(CURDATE(), INTERVAL(1-DAYOFWEEK(CURDATE())) DAY), INTERVAL-7 DAY)) AS LASTSUNDAY
Why have API import at all if API Enrichment is the same except with the ability to process inputs?
Also would love to see an option to loop within the BODY rather than looping the whole BODY.
Neat solution! I’d recommend giving the Date and Time Import
and Add Date and Time
steps a try
What do you mean about looping within the BODY?
The enrichment step is primarily meant to be used to operate on rows of data, but I see your point!
For example if I wanted to have a single Slack payload with multiple records:
{
"blocks": [
{
"type": "section",
"fields": [
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>"
}
}
]
}
I need the ability to loop over the fields array in order to generate the correct payload.
Having some sort of looping construct would be great. For example, a simple logic-less templating framework like Moustache offers:
<h1>{{header}}</h1>
{{#items}}
{{#first}}
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>
{{/link}}
{{/items}}
Got it. If I’m understanding correctly, you should be able to use the API Enrichment step for that to cycle through rows. If that’s not correct, would encourage you to post in #feature-requests! Our product and engineering teams use that list to help prioritize features.
Hey Geoff!
You can build up JSON bodies like this, where there are arrays of objects taken from rows of data.
You will want to first use a Text Merge to create the sets of objects in the array. So that would be using that step to create a column which has the value of:
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
}
And it will make 1 per row. Obviously it may be different for each type, and you would merge in your columns to create each object.
Now, use a Merge Values step to combine rows that need to be bundled into the same JSON payload. Either by grouping by a specific column, or not grouping, so that every row is merged. Use a comma with no space after it as the delimiter.
That will give you this in a column:
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
},
{
"type": "plain_text",
"text": "*this is plain_text text*",
"emoji": true
}
Now you can merge that column into your array in your payload body so that it is wrapped in [square braces]
and you can add all the other trimmings around it!
Let me know if that works.