# Passing variables to API Import

**URL:** <https://community.parabola.io/t/passing-variables-to-api-import/484>\
**Category:** Ask a question\
**Created:** [May 9, 2020, 3:48am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484 "2020-05-09T03:48:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geoff\_Bowers](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/geoff_bowers/32/93_2.png) [@Geoff\_Bowers](https://community.parabola.io/u/Geoff_Bowers)\
**Post date:** [May 9, 2020, 3:48am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/1 "2020-05-09T03:48:21Z")

</div>

Is it possible to pass variables into API Import?

I need an endpoint like so:

```auto
https://app.asana.com/api/1.0/tasks/?project=2274838407251433&completed_since=2020-05-10

```

Where `completed_since=` has a value of `now()`

---

<div class="post-metadata">

**Author:** ![Varun\_Goel](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Varun\_Goel](https://community.parabola.io/u/Varun_Goel)\
**Post date:** [May 9, 2020, 9:04am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/2 "2020-05-09T09:04:09Z")

</div>

Yes try the API Enrichment feature… you can use curly braces to reference values from data you have at the time

---

<div class="post-metadata">

**Author:** ![andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/andrew/32/36_2.png) [@andrew](https://community.parabola.io/u/andrew)\
**Post date:** [May 10, 2020, 6:15pm UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/3 "2020-05-10T18:15:48Z")

</div>

+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.

---

<div class="post-metadata">

**Author:** ![Geoff\_Bowers](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/geoff_bowers/32/93_2.png) [@Geoff\_Bowers](https://community.parabola.io/u/Geoff_Bowers)\
**Post date:** [May 13, 2020, 12:40am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/4 "2020-05-13T00:40:36Z")

</div>

> [@andrew](#):
>
> 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:

```sql
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.

---

<div class="post-metadata">

**Author:** ![andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/andrew/32/36_2.png) [@andrew](https://community.parabola.io/u/andrew)\
**Post date:** [May 13, 2020, 7:24am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/5 "2020-05-13T07:24:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Geoff\_Bowers](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/geoff_bowers/32/93_2.png) [@Geoff\_Bowers](https://community.parabola.io/u/Geoff_Bowers)\
**Post date:** [May 13, 2020, 11:50pm UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/6 "2020-05-13T23:50:54Z")

</div>

> [@andrew](#):
>
> What do you mean about looping within the BODY?

For example if I wanted to have a single Slack payload with multiple records:

```auto
{
	"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](https://mustache.github.io/#demo) offers:

```auto
<h1>{{header}}</h1>

{{#items}}
  {{#first}}
    <li><strong>{{name}}</strong></li>
  {{/first}}
  {{#link}}
    <li><a href="{{url}}">{{name}}</a></li>
  {{/link}}
{{/items}}

```

---

<div class="post-metadata">

**Author:** ![andrew](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/andrew/32/36_2.png) [@andrew](https://community.parabola.io/u/andrew)\
**Post date:** [May 14, 2020, 7:22am UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/7 "2020-05-14T07:22:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brian](https://sea2.discourse-cdn.com/flex020/user_avatar/community.parabola.io/brian/32/11_2.png) [@brian](https://community.parabola.io/u/brian)\
**Post date:** [May 18, 2020, 6:18pm UTC](https://community.parabola.io/t/passing-variables-to-api-import/484/8 "2020-05-18T18:18:57Z")

</div>

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:

```auto
				{
					"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:

```auto
				{
					"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.
