TestProject Forum
Powered by leading experts in the test automation community

RESTfulAPI Client Addon: Store POST response value and use it in subsequent GET query

Hi
I am current doing a POC for API testing using RESTful API addon. I am doing a POST request to Auth0 account to get access_token. I would like to store this value in a variable and use it in my subsequent requests. Any help around this is much appreciated.
Thanks
Krish

Hi @krish.murthy,

Using the RESTful API Client addon, you can send HTTP requests and get the response back.
On each action of this addon (i.e. GET, POST, PUT, etc.), you have an output parameter for the response that you are getting back from the server. You can store this response inside an output parameter and later, parse it and extract whatever you need from it.

Using the “Json Operations” addon, you can easily extract values from the server response using JsonPath syntax.

You can find more information about the “RESTful API Client” addon here:

  1. https://blog.testproject.io/2018/11/28/rest-api-testing-testproject/

  2. YouTube tutorial part 1: https://www.youtube.com/watch?v=3hm5APcxbx4&list=PL5qXkPB0T6VeyY1nGBf7hU8G2Zx3LrDwg&index=10&t=0

  3. YouTube tutorial part 2: https://www.youtube.com/watch?v=kqzQWIBW1iY&list=PL5qXkPB0T6VeyY1nGBf7hU8G2Zx3LrDwg&index=11&t=0s

Of course, you are always welcome to ask your questions here :slight_smile:

Kind regards,
Amit

@amit.yahav So do you think this way is the right approach - I have stored the access token value like this
image

And I am using it in the subsequent GET with a header value as "Bearer patientaccesstoken"

But when I do this way I got response as - parameter is invalid

So does this mean that I should use the json parser to extract in a proper way?

It depends on how the server returns this token.
If it a json file, then just storing the response is not enough.

Let’s say that the server returns something like this:

{
    "accessToken": "SOME_VALUE"
}

Then you will have to extract the value from it and only then use it in the GET request. You can see how I did it here:

Okay i have now added the json operations addon . But i dont see the field called “JsonFile” as like in your screenshot. Do I have to recreate that step to see that specific field. I only see these fields in my TP request screen
image

You are not using the same action that I did.
However, this should work too (again, depending on how your server returns the data in the response)

Right I got it now. But Should I do this step after I do a POST to get the access token? Or should I do it in one step using this Get value from JSON using jsonpath. Bit confused here.

You can actually do it in both ways.
I think that extracting the token directly from the POST request is much easier, since it saves you the extra step.

But then my question is when I do it in the same request - I can only have one action right? I cant have another action inside the same request to use “get value by json”

image

You are right.
But you don’t need to. Extracting the token from the POST request or from the other action is the same.

woop woop :slight_smile: i made it to work

That’s great @krish.murthy!!