Select to view content in your preferred language

HTTP basic authentication method in Survey123 javascript

2664
11
Jump to solution
12-16-2022 06:23 AM
MartinBrandi
Occasional Contributor

Hi, From a Survey123 Javascript, I would like to call an API with the HTTP basic authentication method. This is the requirement from the API supplier:

Authentication
Each request requires authentication, which is performed using the HTTP basic authentication method. The header contains the authentication data in the form "Basic username:password" where the phrase "username:password" is Base64 encoded. Username and password are set individually for each external system.

I have tried with:
var url = `<MyUser>:<myPassword>@branchekataloget.dk/api-gateway/Branchekataloget/products?${parameters}`

xmlhttp.open("GET",url,false);
xmlhttp.send();

But get the answer:
Error in <MyScript>.js : 28:1 Expected token `;'

Hope you can point me in the right direction 🙂

0 Kudos
11 Replies
MartinBrandi
Occasional Contributor
Hi  Derek
No don't know what is going on with the checkmarks??
I am not a programmer so bear with me. I just did what Zach suggested and used Postman to setup the HTTP basic authentication method
MartinBrandi_0-1701887289436.png

 

And then copyed the code from Postman to the Script in Survey123: 

MartinBrandi_1-1701887486537.png

Don't know if this was any help at all.

Regards

Martin 

 
0 Kudos
DerekKonofalski
Frequent Contributor

Hi, @MartinBrandi - Sorry about all the comments, then. Wasn't sure why they were getting immediately checked and marked as the solution either.

Understood that you're not a programmer. Do you know how you've set up the username and password in that in order to not expose it publicly? The part that I'm most concerned with is the part that's cut off in your screenshot.

0 Kudos