Forum Discussion

armygrad's avatar
2 years ago

Set access_token Global variable from a jason response



Im trying to set a global variable token from a json response below is my response


"access_token": "94g4hCtN78",
"token_type": "Bearer",
"expires_in": 86400


Many Thanks

4 Replies

  • Hi armygrad,

    try to use json.tokenData.access_token to get the token string and put it in Property variable:
    testSuite.setPropertyValue("myToken", json.tokenData.access_token);  //in a defined Property myToken



    • armygrad's avatar

      Thanks for replying would be from a property transfer test step?

  • jkrolczy's avatar
    Regular Contributor

    By different ways to extract the token value from your response.
    If you can isolate that value into a variable, then you could use the following code example.

    Use Groovy script step here.


    ** Note: tokenID is my custom project properties


    def tokenid = extractedValue2" Token value: "+tokenid);

    testRunner.testCase.testSuite.project.setPropertyValue( "tokenID", tokenid );


    Global variable syntax shown below.


    Very useful webpage:


    These script lines are used to set the value to the local and global property.


    testRunner.testCase.setPropertyValue( " LocalPropertyName ", someValue )


    testRunner.testCase.testSuite.setPropertyValue( " LocalPropertyName ", someValue )


    testRunner.testCase.testSuite.project.setPropertyValue( " LocalPropertyName ", someValue )
    ( " GlobalPropertyName ", someValue )