08-09-2017 10:00 AM
I am new to APIs and trying to develop a simple pipeline.
I am authenticating and then searching by first name and last name and expecting the call to return the IDs associated with the person (in this case Roy Graham).
In the pipeline I am first using a Rest Post to Authenticate and then using a mapper to parse out the authentication parameters from the response header that are needed for the subsequent post/get calls. I am then using a copy / join those headers with a JSON generator. In the JSON generator I am inputting request body that I need in order to make the Rest Post Search call.
{
“FirstName”: “Roy”,
“LastName”: “Graham”
}
However I am getting a user not authorized error in the Rest POST call. I do not receive the same error when using a REST get call which leads me to believe its how I am handling/inputting the request body? What is the best way in Snaplogic to input the request body into a Rest Post call?
“error_entity”: “{“message”:“User not authorized”}”
Any assistance is greatly appreciated (11.7 KB)
08-10-2017 08:12 AM
Thanks @tstack
It is now successful.
Few things to note:
HTTP calls are very finicky about syntax and well formation of the attributes.
There needs to be a space after the semi-colon in the cookie header:
‘JSESSIONID=’ + $SessionID + '; ’ + $Token
Also, the X-XSRF-TOKEN header should have just the token value and not ‘XSRF-TOKEN=“…”’. I extracted the token like so:
$Token.match(/=“(.*)”$/)[1]
see the query variable how it is formed.
query: ‘{“FirstName”:"’+$FirstName+‘", “LastName”: "’+$LastName+‘"}’
Attached is my pipeline.
NG_Join_Search1_2017_08_10.slp (8.5 KB)
08-11-2017 11:30 AM
This is great! Thank you so so much. I have been banging my head over here.
2 Questions.
08-14-2017 07:58 AM
Please refer to Accept-Encoding details here
If you want multiple patients sent - I am assuming in one single call, you just have to make an array. Hoping that the REST POST will accept the format.
[
{
"FirstName": "Liz",
"LastName": "Smith"
},
{
"FirstName": "John",
"LastName": "Snow"
},
{
"FirstName": "Barry",
"LastName": "White"
}
]
You can read from a data source such as a table and use the Group By N to collect them into an array like the above. There are other ways of doing this as well but you can try the above method first.
If this is not what you want, let me know.
08-21-2017 02:00 PM
Hello again,
I was able to successfully multple search. However I am now running into the same issue with the PUT call that I was running into with the Post call (user unauthorized). I have formatted (or at least I think I have) the headers vars exactly the same. Any thoughts as to why the something needs to be different in the PUT call then the POST call.
In the pipeline I have the post callNG_UpdSysRec_2017_08_21.slp (12.8 KB)
that is successful as well as the PUT call that is unsuccessful.
Any help is great appreciated!