Beginner Recipe: How to POST JSON Data to the Database via Ambience

Level: Beginner

Steps Used:

  • MongoDB Writer
  • HTTP Endpoint

Scenario:
You need to enter data into an Ambience dataset that comes from an external source in JSON format.

Solution:
Ambience 2020 ETL stores data in MongoDB collections defined using the Ambience Datasets module.

To write into MongoDB, one can use the MongoDB Writer ETL step.

The functionality of an ETL chain can be exposed via the Http Endpoint ETL Step.
So your ETL Chain would look as follows:

In this case we have called our Chainset “MyListener” and the Chain “Run”.

Configure your MongoDB Writer ETL step by selecting the database and indicating the name of the collection in the database to write to.

The Http Endpoint does not need to be configured.

You may save and close the screen.

Testing:

To test out our new endpoint, we need to obtain a URL. Fortunately, this is easy to do in Ambience 202X ETL Designer.

Open the configuration for the Http Endpoint ETL step and click on the clipboard icon next to JSON Endpoint. This will copy the URL to the clipboard.

In this case, the URL will look something like:

https://localhost:1740/etl/MyListener/Run

As this is a POST endpoint, you need to test it using a third-party software like Postman (Windows, Mac, Linux) or CURL.

However, since Ambience requires user authentication, you first need to generate an API token.

For that you may use the API Tokens module. A generated API token looks something like this:

(Avoid using “admin” for your API Token except in local test environments - instead create a user with the minimal access rights and create the token for that user).

Using CURL (on Linux and/or mac) with the API token above, the command will be:

curl -X POST http://localhost:1740/etl/endpoint/MyListener/Run?elx.token=239f9bad-2c14-4e1e-b3e0-eeae964eae57 --data '{"demo": 123, "value": "abc" }'

See Reference:
ETL Designer Manual Page