Unable to get all the API response node details

Hello All,

I am in desperate need of help. I would appreciate, if I could get any help in this regards.

I have a GET method Rest API that uses bearer token. From postman, on passing the details i am able to see json response.

However, if i execute the same request with same sets of headers, some of the nodes are not displayed under response.content.

Attaching the screenshot of the issue

This is my robot file, containing the set of lines

${headers} create dictionary Authorization=${bearer-token} Sec-Fetch-Site=same-origin Sec-Fetch-Mode=cors Accept-Encoding=gzip, deflate, br Accept-Language=en-GB,en;q=0.9 Accept=application/json, text/plain, / Connection=keep-alive

${Response}= GET On Session mysession /?test=${test}&fl_date=${fl_date}&fl_placement=${fl_placement}&fl_category=${fl_category}&fl_type=${fl_type}&fl_store=${fl_store} headers=${headers}

Log To Console ${Response.content}

ISSUE:- All spaces are proper & i am able to get the response. The issue is, session id node is not retrieved & the complete image code.

Hi Sohit,

The answer is likely to be in the request headers, body or cookies, but you didn’t share a comparison of the request details only the response body, so we can see the problem but can’t offer any help to solve the problem.

I suggest you compare each and every entry in the request headers, request body and request cookies and add any that are missing, remove any extras (if there are any extras) and you will probably find the solution.

Dave.

Thank you Dave for your response.

I am attaching 2 screenshots, one from the developer tools (which works the same way as in Postman) & other one from Robot file.

Please let me know if i am making any mistake here.


After making the request body identical (in robot file), i am still unable to get the complete node details.

Hi Sohit,

There are a few potential issues I see here, so these suggestions should give you a starting point:

  1. ${bearer-token} variable, it looks like there are 2 spaces between the word token and the token string, 2+ spaces has special meaning in Robot Framework, so if you need 2 spaces there you’ll need to escape the second one or just use the ${SAPCE} variable i.e. token${SAPCE}${SAPCE}a30b537.....
  2. csrftoken in the cookies, these tokens are usually issued by the application web server, they usually have a limited life span (they are a type of session cookie) typically in the 15-30 minute range
  3. back to ${bearer-token}, the token value itself looks like a session authorisation token so again this would probably be issued by the application web server, and probably has a limited life span typically in the 30-60 minute range

Guessing you’re going to be testing more than 1 api call? To resolve 2 & 3 I would suggest you create a API login keyword that does the following:

  • create the Requests session
  • hit the ${baseURL} to get the csrftoken and set that in the cookies (may happen automatically?)
  • post a login request with a username/password to get the server generated Authorization Token and then set this as a suite variable ${bearer-token}

Then you can just call API login keyword in all your tests or make it a [test / suite] startup keyword

As for the other cookies, I cant see most of them in your robot file but looking at the devtools screen shot, these you should pay attention to:

  • anything starting with _ga is related to google analytics, you can probably ignore them, your application probably doesn’t use them
  • authtoken cookie, see point 3 above
  • authprofile looks similar to authtoken, probably also generated by login
  • userid looks similar to authtoken, probably also generated by login

Your devs should be able to tell you more detail about how to perform a login call to generate those cookie values.

Hope this helps,

Dave.

Hi Dave,

Surely, i will be doing the changes you suggested for point 2.
For point 3, i have tried the same token & executed the request from Postman & i am able to get all the nodes.

So, i believe the span of bearer-token is alive. Even then, in response from requestslibrary, i am not getting the same results.

Attaching the screenshots from Postman.

Request Body Params

Request Body Header

Note:- The token is copied from browser devtools & used in this request body before timeout.

Response Body

Below is the response after using requestslibrary

{“data”:{“variants”:[],“columns_meta”:{“brand”:{“is_sortable”:true,“is_searchabl
e”:true},“packshot”:{“is_sortable”:false,“is_searchable”:false},“category”:{“is_sortable”:true,“is_searchable”:true},“full_name”:{“is_sortable”:true,“is_se
archable”:true},“count”:{“is_sortable”:true,“is_searchable”:true}},“store_explorer_settings”:{“display_caption”:{“label”:"",“enable”:true},“posm”:{“label”:
“Show POSM/BAY”,“enable”:true},“exclusion”:{“label”:“Show Exclusions”,“enable”:false}},“images”:[],“sticker_boxes”:[]},“status”:200}

Note:- The variants array is empty

Hi Sohit,

Not sure what else to tell you, the issue is not Robot framework or requests library, you are getting a valid response, it’s just your request is missing something that your AUT needs before it will return the data you are expecting.

Your application developers should be able to look at the request on the server side and tell you what is missing, as I don’t know the details of your application I have given you generic suggestions based on my experience with many applications, but I can’t know the specifics of your application.

Dave.