HTTP API sources are enabled per account. Contact the Mangrove team to turn them on.
Before you begin
Your endpoint must acceptGET or POST and return CSV or a JSON list of objects, at the top level or inside the response. If your API pages or limits its results, read Paged and limited results first. To read from a Databricks SQL warehouse, see Databricks SQL statements.
You’ll need:
- The base URL, path, required headers and query parameters, and any JSON body for a
POSTrequest. - Credentials, if required: a fixed key or token, or OAuth2 client credentials with a token URL and any required scope. Endpoints that receive credentials must use
https://. - How to select records: after the last value received, within a time range, or the full result every time.
- The event types to create in Mangrove.
Add an HTTP API source
The form has two columns. On the left, set up credentials, the schedule and the connection test. On the right, starting with What each run fetches, describe the request and its response.1
Choose HTTP API
In your project, open Setup → Data feeds. To create a feed, click + Data feed: the Add Data Feed page opens on the Sources step. Select HTTP API, name the feed on Details, then continue to the HTTP API step. To add the source to an existing feed, open the feed and click Add source, then select HTTP API.Display name is optional; leave it blank to name the source after your API’s host.
2
Add credentials
Under Credentials, click Add credential for each secret your request needs and give it a name, such as
api_key. Names start with a lowercase letter and use only lowercase letters, digits and underscores. cursor_value, window_start and window_finish are reserved.Choose the Type:- Fixed key or token: Mangrove inserts the secret as it is.
- OAuth2 client credentials: enter the Token URL, Client ID, Client secret and any Scope. Mangrove obtains a token, reuses it until it expires, and inserts it into the request.
{{api_key}}, with a Copy button and how often the request uses it. Secrets are encrypted when saved, and only account admins can reveal them. Leave this section empty if your API needs no credentials.3
Choose what each run fetches
Under What each run fetches, choose Everything, every run or Only what’s new. With Only what’s new, the variables you put in the request in the next step decide whether each run continues from the last value or fetches the next time window. See Choosing what each run fetches.
4
Describe the request
Enter the Base URL, such as
https://api.example.com, choose the Method, and enter a Path relative to the base URL, without a leading slash. Add Headers, Query parameters and, for POST, a JSON Body as needed.Place variables where your API expects them, such as Authorization: Bearer {{api_key}} in a header. Available tokens lists the credentials and fetch variables you can use; click one to copy it. Variables that can’t be combined with the ones already in use are dashed. See the complete example.5
Describe the response
Choose the Response format, CSV or JSON. For JSON, set Rows are in to the path of the list, such as
data.records, or leave it empty if the whole response is the list. If your API returns numbered pages, set Pages to Paged; see Paged and limited results.With Only what’s new, fill in the cursor fields that appear: Cursor column when continuing from the last value, then Cursor type and Initial cursor.Click Preview response to see up to 100 of the rows the next fetch would read. For JSON, the preview suggests paths to the lists of objects it found; if yours is nested deeper and isn’t suggested, type its dotted path into Rows are in.The preview can’t tell you whether your API returned every matching record. Check its page or row limits separately; see Paged and limited results.6
Test the connection
Click Test connection to check the credentials and endpoint. The button is available once the form is complete; until then, the fields to fix are listed beneath it. The result shows each stage, such as Credentials and Endpoint request, and which one failed. Use Copy diagnostics when contacting support; secrets are left out.
7
Finish setup
For a new feed from a generic HTTP source, click Fetch a sample on the Schema step to define the columns without importing records. If the endpoint returns no rows yet, or the source runs a Databricks SQL statement, upload an example CSV or spreadsheet instead. On Event types, select the event types to create, then save the feed.For an existing feed, save the source and check that its columns match the schema and transformations.
8
Run your first sync
New HTTP API sources start manual. Click Sync beside the source in the Sources table, then check its Last run, the run in Data → Data feed runs, and the resulting events in Data → Events. If the import isn’t what you expected, open the run’s page and click Revert to remove its events; see Checking progress.When you’re happy with the results, edit the source and turn on Fetch automatically in its Schedule section to fetch daily. See Scheduling.
Example: fetch readings by ID
This example API usesafter_id and order to return readings in ascending ID order. Adapt the parameter names and authentication to your API.
Create a Fixed key or token credential named api_key, then configure:
For this response:
id, recorded_at and value. After a successful fetch it saves cursor 2, so the next fetch sends after_id=2. Previewing the response or fetching a sample does not move the saved cursor.
Using variables in the request
Variables can go in the path, query parameter values, header values or the JSON body. Use credential names and the variables for your chosen approach; the form flags any other{{name}} before you save.
Continue from the last value
Use{{cursor_value}} to request records after the saved cursor, returned in ascending order; see Continue from the last value for choosing a safe cursor.
Fetch the next time window
Use both{{window_start}} and {{window_finish}}, without {{cursor_value}}. For an API with from and to parameters, add them under Query parameters:
Use your API’s parameter names and check that it includes the start, excludes the end and returns the full interval. Mangrove cannot check these filters for you. Bounds are UTC timestamps or Unix epoch values, according to Cursor type.
Set Settle lag (seconds), Maximum window (seconds) and Fetch limit (per hour) under Advanced options > Window timing.
Paged and limited results
If your API splits a JSON result into numbered pages and reports how many pages there are, set Pages to Paged:- Page parameter: the query parameter your API reads the page number from, such as
page. Paging sets it, so leave it out of Query parameters. Set the page size there instead, if your API takes one. - Page count is in: the path to the total number of pages in the response, such as
meta.total_pages. Preview response suggests paths that hold a page count.
- When continuing from the last value, an API that accepts the last returned cursor continues one page per run. To keep up, each run must import records faster than they arrive.
- With time windows, every record in the window must fit in one response. A truncated response can skip records, because the cursor moves to the window’s end. If your API limits page size, set a Maximum window small enough that each window fits; a scheduled source fetches the following windows until it catches up, spaced by Fetch limit (per hour) if set.
- An API that requires following a separate pagination token cannot be fully collected by this connector alone. Contact the Mangrove team to discuss options.
How responses become rows
A CSV response is imported as it is. For JSON, each object in the list at Rows are in becomes a row, with one column per key. Nested objects and lists are kept as JSON text in their column. A response can have up to 500 distinct keys.Attaching documents
If your rows reference files that the same API serves, such as delivery tickets or lab certificates, Mangrove can fetch each file and attach it to its event as evidence. Your data feed’s transformation names the file for each row with asource_file evidence entry; see the transformation contract.
Turn on Documents in the source form and set:
- Folder: the lowest folder under the base URL that holds every file, such as
documents. Files outside it are refused. - If a file can’t be fetched: for a file that is missing or can’t be fetched, Publish and flag publishes the row without the file and shows a warning on the run, and Fail the row fails the row, naming the file. A path outside the folder, a file over 50 MB or an unsupported file type fails the row under either setting.
- Send with file requests: tick the request headers that file requests send, such as
Authorization. File requests send no headers unless you tick them, and a ticked header can use credentials but not the cursor or window variables.
Databricks SQL statements
To read from a Databricks SQL warehouse, set Connector type to Databricks SQL Statement when you add the source. The connector type can’t be changed later. Mangrove submits your SQL statement, waits for it to finish and reads its results.- Base URL: your workspace URL, such as
https://your-workspace.cloud.databricks.com, with Pathapi/2.0/sql/statements. - Method:
POST. - Credentials: add a token credential and reference it in an
Authorizationheader, such asBearer {{databricks_token}}. - Body: the statement request as JSON, with your
warehouse_idandstatement, and optionallycatalogandschema. SetformattoJSON_ARRAYanddispositiontoINLINEorEXTERNAL_LINKS. The form’s example body usesEXTERNAL_LINKS, since Databricks caps inline results.
{{ variables. Bind the cursor or window as named statement parameters instead, and refer to them in the SQL as :window_start and :window_finish, or :cursor_value:
/Volumes/catalog/schema/volume, and files are fetched through the Databricks Files API.
Limits
Under Advanced options > Request limits:- Response size limit (MB): the most data one response, or one page, may return. Default and maximum: 50 MB. If a response is larger, the run fails without moving the cursor; request less data, for example with a smaller Maximum window.
- Page limit: with Paged set, the most pages one run may fetch. Default: 100; maximum: 1000. A fetch that reports more pages fails before reading page 2.
- Fetch deadline (seconds): how long the whole fetch may take, every page of a paged fetch and any OAuth2 token request included. Default: 300 seconds; maximum: 1800. A Databricks statement source labels this Response deadline (seconds).
Troubleshooting
Connection failed
Connection failed
- Check which stage failed in the Test connection result: Credentials or Endpoint request.
- For OAuth2, check the token URL, client ID, client secret and scope. Receiving a token does not guarantee the API accepts it.
- When your API rejects the request with a 4xx status, such as 401 or 404, the result includes the start of its error message.
- Check that network rules allow Mangrove to reach the endpoint.
Cannot save the source
Cannot save the source
Save, or Next when creating a feed, stays disabled until the form is complete. Hover over it, or look under Test connection, for the list of fields to fix; each one is also highlighted. Common causes:
- A credential has no secret entered.
- The base URL or OAuth2 token URL starts with
http://while credentials are configured. Usehttps://. - A credential name is missing, repeated, reserved, or uses characters other than lowercase letters, digits and underscores.
- The request uses a
{{name}}that is neither a credential nor a variable for your chosen approach, or mixes{{cursor_value}}with the window variables. - The path starts with a slash or is a full address, a
GETrequest has a body, or aPOSTbody is not valid JSON. - When switching an existing source to time windows, enter Start the next window at. See Changing fetch modes.
No rows found in the response
No rows found in the response
- Check that Response format matches what the endpoint returns and that the request selects a range containing data.
- For JSON, click Preview response and pick the list of objects for Rows are in. Leave it empty only when the whole response is the list.