Rest Resource asset's configuration


(Harinder Singh) #1

Matrix Version: 6.26.1

I am trying to integrate with Shelterbuddy system to pull out the list of the pets.

API Docs:
https://shelterbuddy.atlassian.net/wiki/spaces/SbApi/pages/25198637/Authentication
Auth URL: https://demoURL.shelterbuddy.com/api/v2/authenticate?username=*********&password=#####
List URL: https://hawkesburynsw.shelterbuddy.com/api/v2/animal/list

I’ve been able to configure and retrieve the list in Postman, but I’m struggling to replicate the same behavior in Matrix using the REST Resource asset. While I’ve managed to handle the authentication part, I’m not sure how to execute multiple chained HTTP requests.

Can anyone please guide?


(Iain Simmons) #2

Hi @harinder.singh,

I’d recommend you add a metadata field to the REST Resource (e.g. sb-auth-token, just a text field) that is not displayed on the frontend, and will be used to contain the token.

Then add a trigger. The trigger will fire on ‘REST Response Received’, with a condition of the asset being the REST Resource, and a REST Response condition to check the status code to see if it is 401 or 403, whichever one you get when you are not authorised.

The first trigger action should use Call REST Resource and do the auth, then if you print the token in the JS processing, you can make it available as a session variable (name it sb-token or something).

The second action should set the value of that metadata field to the token.

The third action is to Redirect to URL and just redirect to the original REST Resource again.

The REST Resource will need to use a Request Header of:

sb-auth-token: %asset_metadata_sb-auth-token%

And you probably want it to handle the errors in case it shows something before the trigger runs.

Hope that works for you!

Cheers,
iain