How to assign a variable which holds another variable

Dear everyone

I am working on a HTTP request, where I have to convert a piece of a Python code to UiPath.

More specifically, we are talking about this line of code listed below

image

I have succesfully assigned a variable named “headers” and given it a dictionary where the first key/value pair is {{“accept”, “application/json;charset=utf-8”}…} however, the second key/value pair I am a bit confused as to what to do since there is a variable inside the assignment. Doing simply {{“accept”, “application/json;charset=utf-8”}, {“authorization”, “Bearer {access_token}”}} obiviously gives an error. How do I correctly insert an variable into my other variable in the assignment activity?

PS. You may assume that access_token already exists and is correctly assigned.
PSS. I do not know the correct theoretical term for this, if you know, please let me know so I can become better at explaining my future errors and struggles :slight_smile:

Thank you beforehand and have a wonderful day/ night forward!

Yours sincerely…
Nemanja. V

@nmjvk

Ideally you can use replace activity by using a place holder for access_token

like dict("Key2") = dict("Key2").ToString.Replace("access_token",str_AnotherVariable)

cheers

Dear Anil

Thank you very much for your swift response. Unfortunately, I am not able to produce the desired output following your instructions.

Here is my access token
image

and here is my dictionary at where I am trying to replace the second value with the actual access token (access_token1)

When running the process, the first key/value pair is correct, bot the second is issing it’s token in the value field.
image

Any suggestions to what I might be doing wrong? :slight_smile:

cheers

@nmjvk

If this is happening after replace activity then it Looks like your variable might be empty.

If it is happening before the relace only then access token is not being assigned only…please run in debug mode and check the locals pane after each step into and see whaere the data is getting empty

Cheers

1 Like

Dear Anil

You are right. My variable was empty even though I initialized it. Doing a simple “Assign” activity before declaring the headers fixed this issue. I am now getting the correct output, thank you very much sir Anil!

Cheerfully cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.