Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..
1510 views

Cannot obtain dynamic JSON data returned from an API POST call

I'm trying to obtain dynamic data in a buffer that has been formatted as JSON. If I make the POST call using Postman I get the returned JSON body below: I would like to obtain that "SRId" value to use in a PUT call that follows the POST. I've read that I should be using web_reg_save_param_json but when I use it in my LR script (see below) I get an JSON Query error (see below in red) in my LR script I've created a parameter file called "Body" to capture data. 

RETURNED JSON BODY from POSTMAN APPLICATION

{
"SRId": 979593,
"SRDefinitionName": "ePolicy",
"SRGuid": "1837e2e2-8122-48b8-8764-c17f885b4682",
"ParentId": -1,
"CaseId": null,
"Status": "XML Export TX1214 - Canceled",
"CurrentWorkflowTask": "83743a90-a37d-4205-84e9-89d544133b3b",
"CreateDate": "2017-12-20T14:26:55.55014-05:00",
"DueDate": "2017-12-21T14:57:00-05:00"

}

LOADRUNNER SCRIPT SNIPPET

web_reg_save_param_json(
        "ParamName={Body}",
        "QueryString=$.SRId",
        SEARCH_FILTERS,
        "Scope=Body",
        "SelectAll=Yes", 
        LAST);

    
 web_url("127.0.0.1:12800", 
        "URL=http://127.0.0.1:12800/", 
        "Resource=1", 
        "RecContentType=application/json", 
        "Referer=", 
        "Snapshot=t1.inf", 
        LAST);
        
    lr_think_time(13);

    web_url("127.0.0.1:12800_2",
        "URL=http://127.0.0.1:12800/?name={Body}",
        "Resource=1",
        "RecContentType=application/json",
        "Referer=",
        "Snapshot=t4.inf",
        LAST);

 ERROR
Action.c(57): Error -35060: No matches were found for the specified query: "$.SRId"  [MsgId: MERR-35060]
 
Tags (1)
0 Likes
7 Replies
Highlighted
Honored Contributor.
Honored Contributor.

Re: Cannot obtain dynamic JSON data returned from an API POST call

can you please post the web_url("127.0.0.1:12800" step response (from the log/snapshot)?

 

Micro Focus Performance Core.
Functional Architect
your performance, our passion!
0 Likes
Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: Cannot obtain dynamic JSON data returned from an API POST call

Moshka - Thank you so much for your kind reply, please see below the requested information. If you need anything else at all don't hesitate to ask.

 

Action.c(44): Notify: Transaction "Create Policy" ended with a "Pass" status (Duration: 1.2727 Wasted Time: 0.0311).
Action.c(48): web_reg_save_param_json started [MsgId: MMSG-26355]
Action.c(48): Registering web_reg_save_param_json was successful [MsgId: MMSG-26390]
Action.c(57): web_url("127.0.0.1:12800") started [MsgId: MMSG-26355]
Action.c(57): Warning -27792: Failed to connect to server "127.0.0.1:12800": [10061] Connection refused [MsgId: MWAR-27792]
Action.c(57): Error -35060: No matches were found for the specified query: "$SRId" [MsgId: MERR-35060]
End auto log messages stack.

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: Cannot obtain dynamic JSON data returned from an API POST call

please change the log level to extended (Run time settings-> Logs, Coose "extended log" and check all teh selection boxes). and post the replay log again.

 

thanks

Micro Focus Performance Core.
Functional Architect
your performance, our passion!
0 Likes
Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: Cannot obtain dynamic JSON data returned from an API POST call

Here you go: Thanks again

 

Action.c(44): Notify: Transaction "Create Policy" ended with a "Pass" status (Duration: 7.7767 Wasted Time: 0.0311).
Action.c(48): web_reg_save_param_json started [MsgId: MMSG-26355]
Action.c(48): Notify: Parameter Substitution: parameter "Body" = "Value"
Action.c(48): Registering web_reg_save_param_json was successful [MsgId: MMSG-26390]
Action.c(57): web_url("127.0.0.1:12800") started [MsgId: MMSG-26355]
Action.c(57): t=12166ms: Closed connection [0] to dev.ifsautomation.com:443 after completing 2 request(s) [MsgId: MMSG-26000]
Action.c(57): t=12166ms: Connecting [0] to host 127.0.0.1:12800 [MsgId: MMSG-26000]
Action.c(57): Warning -27792: Failed to connect to server "127.0.0.1:12800": [10061] Connection refused [MsgId: MWAR-27792]
Action.c(57): t=13171ms: Closed connection [0] to 127.0.0.1:12800 after completing 0 request(s) [MsgId: MMSG-26000]
Action.c(57): Search registration for "Value" parameter is filtered by "Scope" [MsgId: MMSG-26000]
Action.c(57): Error -35060: No matches were found for the specified query: "$SRId" [MsgId: MERR-35060] [Time:2018-01-04 09:19:24]
Action.c(57): Notify: Saving Parameter "Value_count = 0".
Action.c(57): web_url("127.0.0.1:12800") highest severity level was "ERROR", 0 body bytes, 0 header bytes [MsgId: MMSG-26388]
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

 

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: Cannot obtain dynamic JSON data returned from an API POST call

Action.c(57): t=12166ms: Connecting [0] to host 127.0.0.1:12800 [MsgId: MMSG-26000]
Action.c(57): Warning -27792: Failed to connect to server "127.0.0.1:12800": [10061] Connection refused [MsgId: MWAR-27792]
Action.c(57): t=13171ms: Closed connection [0] to 127.0.0.1:12800 after completing 0 request(s) [MsgId: MMSG-26000]

 

the conection to the server failed -> no message sent -> no message recieved -> nothing to extract.

you need to check if the server is up before running the script or if it crashed during the script execution.

Micro Focus Performance Core.
Functional Architect
your performance, our passion!
0 Likes
Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: Cannot obtain dynamic JSON data returned from an API POST call

Moshka - Again thank you for your reponses, I have verified that the server is up and is responding I can run a Postman collection at the server at the same time and it behaves normally so I know for sure it is up and 100% functonal. Is there another way to capture the dynamic JSON value in red below I need without using web_reg_save_param_json?  

 

RETURNED JSON BODY from Server

{
"SRId": 979593,
"SRDefinitionName": "ePolicy",
"SRGuid": "1837e2e2-8122-48b8-8764-c17f885b4682",
"ParentId": -1,
"CaseId": null,
"Status": "XML Export TX1214 - Canceled",
"CurrentWorkflowTask": "83743a90-a37d-4205-84e9-89d544133b3b",
"CreateDate": "2017-12-20T14:26:55.55014-05:00",
"DueDate": "2017-12-21T14:57:00-05:00"

}

 

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Re: Cannot obtain dynamic JSON data returned from an API POST call

happy to help.

 

i think that the json correaltion API that you wrote should work, the current problem is that the script is failing to generate a valid response from the server.

i think that there is a correlation and/or a header missing.

Micro Focus Performance Core.
Functional Architect
your performance, our passion!
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.