Skip to main content

Im having trouble configuring a JSON Reader to pull data from a REST API (JSON formated). 

The problem is that in order to successfully call a query to the REST API (via a URI), there first needs to be sent an authorisation request as separate formatted URI sent ahead that contains a UserID code and a 'Secret' code (ie password) within the URI.

 

The JSON reader has a single web address field (which works well for other applications). To solve this particular problem there would have to be two URIs sent - one to send the Authorisation request and generate a session ID (with the authorisation held in cookies or similar), followed another to submit the data query. I tried the 'Network authorisation' entering the userID and secret into the respective field without success. Have also tried the HTTPCaller and JSON transformers.

 

I dont know enough about FME or API calls to configure this properly, so wondering if there is some advanced use of the JSON reader / transformers that would achieve this, like a pre-fetch URI call. Id be very grateful for any advice. With thanks.

You can solve this by either configuring a Web Conection in Tools FME Options or by using two HTTPCallers to fetch the json file.

Either way you have to use a FeatureReader.

My favorite solution is to use two HTTPCallers. The first one sends the authorization URI and is configured to Save Cookies and the second one is used to sent the URI command to fetch the json file. You can either store it in an attribute and format it using the JSON transformers or (my favorite but more disk intensive) save the response body as a .json file in a TEMP PATH and send the output to a FeatureReader set as the flavor of JSON that the API returns and Dataset to _response_file_path attribute.

To store files in a TEMP PATH use TempPathnameCreator in front of the HTTPCaller that is set to Save Response Body to File, Create a New File Per Feature: Yes, Output Folder: _pathname attribute from TempPathnameCreator.


You can solve this by either configuring a Web Conection in Tools FME Options or by using two HTTPCallers to fetch the json file.

Either way you have to use a FeatureReader.

My favorite solution is to use two HTTPCallers. The first one sends the authorization URI and is configured to Save Cookies and the second one is used to sent the URI command to fetch the json file. You can either store it in an attribute and format it using the JSON transformers or (my favorite but more disk intensive) save the response body as a .json file in a TEMP PATH and send the output to a FeatureReader set as the flavor of JSON that the API returns and Dataset to _response_file_path attribute.

To store files in a TEMP PATH use TempPathnameCreator in front of the HTTPCaller that is set to Save Response Body to File, Create a New File Per Feature: Yes, Output Folder: _pathname attribute from TempPathnameCreator.

Thanks very much that was very helpful, the two HTTPCallers worked well.


Reply