Set Authenication Header Dynamically

I am sure this was asked earlier. I tried searching and couldn’t find a solution. If there is a post with the solution, please point me to that.

I want to set the “Authentication” header to “Basic base64 encoded string of username and password”.

How do I dynamically generate the base64 encoded string and pass it to the Authentication header? I do have input fields “User Name” and “Password”. The user will enter the username and password and I want to use these values to then invoke the REST API.

Any hep is greatly appreciated.

Thanks,
Arun

I believe you would need to do this with Javascript using the Web Viewer. This topic has a demo of that: Base64 encoding in drag and drop - #9 by muneer

And this has a script and screenshots: [Solved] how do I base64 encode an image? - #2 by kartik14

1 Like

Thank you. Using Web Asset worked. Now I am running into an issue with the Web API Get Call. It works in Postman. However, when I test it out in the Thunkable Live, I get “null” for json response. I checked the status and it seems to be fine.

and here is the json that I am expecting to get back

Two things:

  1. The API returns JSON but you are getting the property of an object. This is correct but you are providing JSON instead of an object. To fi this, you have to use the get object from JSON block in front of the green response block.

  2. Once you do that, you will be able to get the “items” property from the API response. However, that property is an array (list) of objects. So you won’t be able to view it as a label’s text as you’ve tried above. Instead, you need to get specific properties that you want from that array.

You might want to watch my tutorial video here. It explains how to copy & paste the full JSON response into https://codebeautify.org/jsonviewer so you can understand the structure and then from there, it shows you how to parse out specific values (properties).

If you just want to play around with all this, you can set a label’s text to get property "items[1].links[1].href" of object [get object from JSON] [response] and you should see “the first url in that screenshot” appear in the label.

If you can’t get it to work, post updated screenshots and I can see if I can help you. But again, that video might be a good starting point if you want to better understand all of this.

1 Like

Thank you. I changed it to " get object from JSON block in front of the green response block." and it worked :slight_smile:

Appreciate the help.

2 Likes