Creating a Metric from a REST Endpoint

Generate a data feed from a REST URL, then create a metric from it.

  1. POST /data_feeds/generate?type=rest — generate a feed that pulls from a URL (see the Data Feeds guide for the full field list):

    { "url": "https://api.example.com/v1/orders", "method": "GET", "contentType": "csv", "name": "Orders" }
  2. POST /metrics — see Creating the metric from the feed below.

Creating the metric from the feed

POST /data_feeds/generate returns a feed with an id and columns[] (each with its own id); the metric then points at the feed itself, not at any underlying datasource:

{
  "name": "Order Amount",
  "description": "Order total pulled from the orders endpoint",
  "sourceType": "DATAFEED",
  "sourceId": "<feed id>",
  "fieldId": "<id of the value column>",
  "dimensions": [
    { "name": "Status", "fieldId": "<id of the status column>" },
    { "name": "Region", "fieldId": "<id of the region column>" }
  ]
}

Use the id of a metric-shaped column (e.g. a numeric column with an aggregation) for fieldId. If the feed has more than one date column and the metric should key off a specific one, set timeRefId to that column's id; otherwise it can be omitted. Other columns you want as filter/group-by dimensions go in dimensions[], each with that column's id as fieldId.


Did this page help you?