Skip to main content

Hello everyone,

 

I've recently been doing some work using HTTPCallers to connect and authenticate to an API. The basic flow is that the first HTTPCaller hits the login endpoint. The credentials (username & password) are passed as application/x-www-form-urlencoded values.

 

An XML response is sent which contains a Session ID. This is then passed through to all subsequent HTTPCallers via the header as Cookie - ASessionID=<Our session ID>. This all works very well, but I've been asked if I could move the whole authentication part into a nice secure easy to use Web Connection.

 

I've done similar before, so thought this would be a fairly easy task, but alas, I've hit a bit of a wall when it comes to the Access Token Response. Unfortunately, the login call to this particular API only returns XML and will not return a lovely JSON response for FME to parse and handle. I was under the impression that FME should be able to look at a JSON or an XML response, but I'm having no luck.

 

Untitled 

Is there some way to get FME to realise that the response it's looking at is in fact XML? I've tried to change the Access Token Request HTTP Header "Accept" to application/xml among other things. Is there a trick to the way I have to format Token Object Key?

 

PS. I realised it was failing due to seeing the response as JSON due to the following error within my workspace when trying to run it:

 

WARN  |JSON Error: Unable to read response from update access token request. JSON Response: <?xml version="1.0" encoding="UTF-8"?>....
WARN  |Unable to obtain updated authorization for web connection 'Asite', credentials may be invalid

 

 

Many thanks for your help in advance!

 

Kind regards

 

Ryan

Hi all,

 

It seems I've been able to find a work-around to this. The only caveat is it requires FME Server.

I've put my workaround below in the hopes that if anyone else runs into this they have something to try.

 

Seeing that the API is a third-party one, I ruled out them making changes to respond with JSON. Also, the chances of a change like this being made within FME in the immediate future are slim, so I had to figure out another option.

 

What if there was something sitting between my initial call to the API? Something that could pass the credentials from my call to the API, receive the response and then change the format to JSON and send it back as a response to the initial call? Enter: FME Server Data Streaming Service.

 

Asite API Call DiagramEssentially, I had to write a simple workspace which takes the parameters (Username & Password) for the API, calls our API via a HTTPCaller, grabs our token/session id and then formats and writes this to JSON. The workspace is called via a webhook URL, the response then contains our JSON token.

 

This workspace will sit on FME Server, but the Web Connection itself, instead of pointing to the API auth URL, it will point to the URL to fire this workspace.

 

I hope that helps somebody!

 

Kind regards

Ryan


Reply