Skip to main content

Hello

 

I have a scenario where a Web Request is made to get an AccessToken.
The result is then stored into a variable] named StoreResult as a Multiline of Text].

 

The result is pretty long and amongst the lines, there is this I am interested at:

{"access_token":"QS27hDdFvfqTPSFElG0vH8Y0h7Eu9Gjt",

 

9858iC8FFC1E7188C470F.jpg

 

How would I be able to extract only the access token value?
From my understanding, I need to convert the Multiline of Text into a Collection value?
Then use the collection to extrat the data?

May sound good in theory but stuck in practially 😞
Please advise...

 

Hi,

You may be able to use a regular expression to extract what you want but I would have to see the all the output of the web request to be able to assist further.

Hello



 



Yes, the Regular Expression functions sounds promissing.



Let me start from the beginning:



 



Note: I had to rename [storeResult] into [storeResult_getToken].



 



1) Call Web Request



2) Store the result into a variable [storeResult_getToken] as Multiple line of Text



3) Crawl through the [storeResult_getToken] and store relevant data into seperate variable



4) Reuse those variable to perform POST actions on API etc. in the other steps



 



Now, I manged to get the desired results from the Web Request.



The result is stored into the variable [storeResult_getToken] as following:



{"access_token":"QQ27hDdFvfqTPSF3lG0vV8Y0h7Eu8Gjt","token_type":"bearer","refresh_token":null,"expires_in":200,"scope":"all"}

 



1st Regular Expression function

The first step is to replace the { " } with nothing and save to the [storeResult_getToken} variable.
Now the next step is to split the data and save the result to a collection variable.



 



2st Regular Expression function





This splits the text by the , (comma) and saves it to the [coll_storeResult] collection variable.



The result in the [coll_storeResult] collection variable is then thores as following:



 



access_token:QQ27hDdFvfqTPSF3lG0vV8Y0h7Eu8Gjt;

token_type:bearer;

refresh_token:null;

expires_in:200;

scope:all


Note: it would be all ine one line but I split it for better visability.



As seen, there are 5 items in total but what I have learned is that these are called [arrays] and it starts counting from [0] zero which means in terms of arrays rules: there are 4 items.



 



1st Collection Operation function





Note: the [int_getcountResult_0] is an interger variable with the value 0.
Remember [0] would be the very first item from the data stored in the collection variable.



 



This would be the result stored to the [accessToken] text variable.



access_token:QQ27hDdFvfqTPSF3lG0vV8Y0h7Eu8Gjt

However, I just need the actual token by itself.
So, we need to apply another Regular Expression function to remove the access_token: bit.



 



 



3rd Regular Expression function





Now, the [accessToken] variable contains only the QQ27hDdFvfqTPSF3lG0vV8Y0h7Eu8Gjt



 



 



Great, I managed to get this 1st step done.



Wow, look at how many steps had to go through to achieve this result.



 



I came accross this Dictionary Variable function on Cloud / O365 .



Wondering if Nintex 2016 onprem has same functions? if so, how to?



 



From my understanding, with the Dictionary function there is no need to split into collections etc/



Because it uses as one unit and is able to identify the collection by the title name only (clever stuff).



 



 



Anyway, as per above steps.



What would be a much better or effecient approach?



 



Furthermore, I am thinking ahead now: how this would help me to manage all the rest of the requirements because the 1st step was to use the token to authenticate my credentials and then the rest of of the workflow is to GET/POST things via the API in order to e.g. create a new user etc etc.



 



My challange is now how to pass on line of codes via the Workflow, as for example:
All the strings need to hold the actual data which is obtainable from the form (stored into variables).



{

"firstName": "string",

"lastName": "string",

"userName": "string",

"phone": "string",

"expiration": {

"enableExpiration": true,

"expireAt": "2021-01-13T11:11:02.388Z"

},

"receiverLanguage": "string",

"email": "string",

"notifyUser": true,

"authData": {

"method": "string",

"login": "string",

"password": "string",

"mustChangePassword": true,

"adConfigId": 0,

"oidConfigId": 0

},

"isNonmemberViewer": true

}


 



Would I do this via the Web Request > POST function?





 



 



Please advise.


Reply