Creating an HTTP API model
-
In Polytomic, go to Models → Add Model → Select your HTTP connection.
-
Name your API model. It is a good idea to name your model after the entities it imports from your API.


-
Select GET or POST for the method body.
-
Enter the path and any required headers and query parameters for the request.
-
You can click the Refresh button below to see the API response based on your configuration.


-
You need to instruct Polytomic how to extract the records from the JSON response. Insert a JSONPath expression into the Extract records field to specify your array of records within the API response. You can learn more https://docs.polytomic.com/docs/using-json-path-for-model-creation, which has some examples as well as links to further reading.
-
After entering the record-extraction JSON Path expression, click Refresh again and you'll see a list of model fields. Select those you want to surface in Polytomic.
-
Commonly, HTTP APIs provide only a subset of the total results at a time. Polytomic can paginate through the results automatically if you specify your API's pagination method. There are two options:
- Next Page URL: enter the JSON Path expression for finding the next page URL in the response body.
- Token: if the response has a token to be included in a header or query parameter, use JSONPath to extract it and specify the field name-value pair as either a header or query parameter.


-
(optional) Join this model to another of your models.
-
Click Save.
Datetime Expressions in Headers and Query Parameters
You may find it necessary to send dynamic datetime values in headers or parameters. An example of this is wanting to send "ten days ago, from the time the sync runs" as a parameter. To support this, Polytomic allows you to write simple datetime expressions in the model Headers and Parameters fields.
Here is an example expression that allows sending a startDate
query parameter that will evaluate to a week ago:
{{ add_days(-7, now()) }}
Token Expressions
You may use an expression to modify the pagination token before it is sent. The pagination token is available in the expression as token()
.
For example, if you wanted to trim timezone information from the token, you could do so with an expression like so: {{ first_n_chars(token, 19) }}
.
Expression Manual
Types
Date
types will render by default as "YYYY-MM-DD".
Datetime
types will render by default as "YYYY-MM-DDTHH:MM:SSZ"
Date
and Datetime
can usually be used interchangeably. However, if you add hours/minutes/seconds to a Date, it will be cast to a Datetime.
Function | Parameters/Return | Notes |
---|---|---|
now() | Returns: Datetime Object representing the current date/time in UTC. | Returns current time in UTC. |
date(year int, month int, day int) | Param | |
date_time(year int, month int, day int, hour int, minute int, second int) | Year/Month/Day parameters as above. | Datetimes are returned in UTC values only. |
extract_years(datetime DateTime) |
| |
extract_months(datetime Datetime) |
| |
extract_days(datetime Datetime) |
| |
extract_hours(datetime Datetime) |
| Time component will be provided in UTC. |
extract_minutes(datetime Datetime) |
| Time component will be provided in UTC. |
extract_seconds(datetime Datetime) |
| |
add_years(years_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
add_months(months_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
add_days(days_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
add_hours(hours_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
add_minutes(minutes_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
add_seconds(seconds_to_add int, datetime Datetime) |
| Negative values are permitted if you would like to specify a time in the past. |
datetime_to_ms(datetime Datetime) |
| You can perform basic math on this number. For example, you can send microseconds or nanoseconds by multiplying. e.g. |
format_datetime(datetime Datetime, layout string) |
| The layout pattern should be Go-compatible Time layout specification. |
first_n_chars(input string, nChars int) |
|
Updated 15 days ago