can we pass multiple args in Get Json Value key? - python-2.7

I'm for now fetching one arg value through Get Json Value key
Create Session Get_Inventory_Details ${Base_URL}
${Headers}= Create Dictionary Content-Type=application/json Authorization=bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InByaXRpc3dhaW4iLCJpYXQiOjE1Njc1MTQ2NDd9.o3qTPbj2KH6AgHpIf1BLV5nOlGL-fR83wSGAYyuWsBQ
${Response}= Get Request Get_Inventory_Details inventorybyOutlet/7 headers=${Headers}
Log To Console ${Response.status_code}
Log Many ${Response.content}
${actual_response}= Convert To String ${Response.status_code}
Should Be Equal ${actual_response} 200
${quantity}= Get Json Value ${Response.content} /0/currentInventory
Run Keyword If ${quantity}>10 Log Threshold Condition Pass ELSE Log Threshold Condition Fail
What can be the possible way out if I want to pass more than one arg in Get Json Value
I have tried
${quantity}= Get Json Value ${Response.content} /0/currentInventory/0/itemid
Reference to Json Data
[
{
"isInventoryOperationEnable":1,
"itemId":1,
"name":"Afghani Chicken Tikka Biryani (Heavy Eater)",
"posName":"Afghani Chicken Tikka Biryani (Heavy Eater)",
"image":"https://d30mle0t4iy75h.cloudfront.net/websiteV2/images/menuItems/AfghaniTikkaBiryani.jpg",
"typeid":2,
"isCombo":0,
"currentInventory":100,
"categoryId":1,
"categoryname":"Biryani",
"subCategoryId":1,
"sequenceInCategory":1
},
{
"isInventoryOperationEnable":1,
"itemId":3,
"name":"Chicken Tikka Biryani (Heavy Eater)",
"posName":"Chicken Tikka Biryani (Heavy Eater)",
"image":"https://d30mle0t4iy75h.cloudfront.net/websiteV2/images/menuItems/ChickenTikkaBiryani.jpg",
"typeid":2,
"isCombo":0,
"currentInventory":100,
"categoryId":1,
"categoryname":"Biryani",
"subCategoryId":1,
"sequenceInCategory":14
}
]
But RobotFramework throws error as :-
JsonPointerException: Document '' does not support indexing, must be mapping/sequence or support __getitem__
Error Message on RobotFramework
Please can anyone help in finding out a way how to pass more than 1 arg in this case
Thank You

Create Session Get_Inventory_Details ${Base_URL}
${Headers}= Create Dictionary Content-Type=application/json Authorization=bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InByaXRpc3dhaW4iLCJpYXQiOjE1Njc1MTQ2NDd9.o3qTPbj2KH6AgHpIf1BLV5nOlGL-fR83wSGAYyuWsBQ
${Response}= Get Request Get_Inventory_Details inventorybyOutlet/7 headers=${Headers}
Log To Console ${Response.status_code}
Log Many ${Response.content}
${actual_response}= Convert To String ${Response.status_code}
Should Be Equal ${actual_response} 200
${response_content_json}= To Json ${Response.content} #To Json is from RequestsLibrary
${quantity}= Set Variable ${response_content_json}[0][currentInventory]
Run Keyword If ${quantity}>10 Log Threshold Condition Pass ELSE Log Threshold Condition Fail
In this case, ${quantity} was 100.
Note two things:
after converting to JSON, variable values can be accessed alike dictionary type variables
To JSON keyword is from RequestsLibrary

Related

You called the function 'Value Selector' with these arguments

I am in the process of implementing a LoanBroker with Mulesoft but have an error message when sending a request. I get the following error message back from Postman and Mulesoft Anypoint Studio:
ERROR 2021-06-27 15:20:51,133 [[MuleRuntime].uber.04: [loanbroker].LoanBrokerFlow_Gr7.CPU_LITE #254be3ee] [processor: LoanBrokerFlow_Gr7/processors/0; event: 7e49f560-d74a-11eb-b598-b66921dc5aa5] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message: "You called the function 'Value Selector' with these arguments:
1: Binary ("" as Binary {base: "64"})
2: Name ("amount")
But it expects one of these combinations:
(Array, Name)
(Array, String)
(Date, Name)
(DateTime, Name)
(LocalDateTime, Name)
(LocalTime, Name)
(Object, Name)
(Object, String)
(Period, Name)
(Time, Name)
1| payload.amount
^^^^^^^^^^^^^^
Trace:
at main (line: 1, column: 1)" evaluating expression: "payload.amount".
Element : LoanBrokerFlow_Gr7/processors/0 # loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount)
Element DSL : <set-variable value="#[payload.amount]" doc:name="Copy_of_setAmount" doc:id="cbcca557-1a69-4cf2-80b1-64333175589d" variableName="amount"></set-variable>
Error type : MULE:EXPRESSION
FlowStack : at LoanBrokerFlow_Gr7(LoanBrokerFlow_Gr7/processors/0 # loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount))
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Can anyone help me?
Thanks
This generally happens when one tries to access inner value of a payload like json but incoming payload is NOT actually a json type.
One could check the payload mediaType and then try to access the amount in order to avoid Value Selector exception.
%dw 2.0
output application/java
---
if( !isEmpty(payload) and payload.^mediaType contains "json" )
payload.amount
else
read(payload, "application/json").amount //best effort
Would recommend creating a separate dataweave file like dwl/set-amount.dwl and referencing it.
You are probably sending some body in the HTTP request from Postman but Mule doesn't know how to read it. Maybe you did not the Content-Type header in the request to let DataWeave know it is a JSON (application/json) or XML (application/XML).
Ensure you are sending the right content type.
I ran into the same situation. I know exactly the base64 is a json. So, I tried to set the MIME Type by
<set-payload value="#[payload]" doc:name="Set Payload" mimeType="application/json"/>
It works for me.

access json body parameters in custom formatter of lnav log file navigator

I'm using lnav to filter and query on top of the custom log file we have created.
As this is a custom log file, I need to create a custom format file and install it using below command to define the structure of the log entries.
lanv -i custom_format.json
Custom format JSON: https://pastebin.com/z7sCVqxd
Though this is working at the high level, I would also like to apply filters using the parameters that are present in body JSON.
The body parameter I've mentioned in the custom formatter is JSON. Not the entire log entry is JSON but only the body parameter value alone is the JSON., In the body parameter only the log level, message and other useful information are present.
Is it possible to use something like,
"level-field" : body.level,
"level" : {
"error" : "error",
"warning" : "info"
},
And also how to define other parameters from the body json to Value for defining "kind" and "identifier" or not
Thanks
So far I've analyzed I couldn't find any direct solution. I went through the documentation of lnav (here) and found out that there are few JSON functions available which we can use to extract the data from JSON based columns.
with mylog as (select jobserver, workqueue, processid, jget('{"' || col_0 || '"}','/LEVEL') level, jget('{"' || col_0 || '"}','/PREFIX') pid, jget('{"' || col_0 || '"}','/MESSAGE') message from logline) select * from mylog where processid = 358812 limit 1
This temporarily solved the problem. But I'm still looking for the support from lnav API itself.

Create Inventory Adjustment giving an error

I am trying to create an inventory adjustment from a MAP/REDUCE script. the record from which i am setting the values is getting ftom a search in getInputData(). In map function i am loading that custom record and setting these values
var newcase_inv_Adj = record.create({type:'inventoryadjustment',isDynamic:true});
newcase_inv_Adj.setValue({fieldId:'account',value:creel_account});
newcase_inv_Adj.setValue({fieldId:'custbody_cp_adjreasoncode',value:creel_reasoncode});
newcase_inv_Adj.setValue({fieldId: 'custbody_c_from', value: name});
newcase_inv_Adj.selectNewLine({sublistId:'inventory'});
newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'item',value:creel_item});
newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'location',value:creellocation});
newcase_inv_Adj.setCurrentSublistValue({sublistId:'inventory',fieldId:'adjustqtyby',value:creel_weigh_oh});
var create_inv_detail = newcase_inv_Adj.getCurrentSublistSubrecord({sublistId: 'inventory',fieldId: 'inventorydetail'});
create_inv_detail.selectNewLine({sublistId:'inventoryassignment' });
create_inv_detail.setCurrentSublistValue({sublistId:'inventoryassignment',fieldId:'receiptinventorynumber',value: creel_casenumber});
create_inv_detail.setCurrentSublistText({sublistId:'inventoryassignment',fieldId:'binnumber',value: creel_bin });
create_inv_detail.setCurrentSublistValue({sublistId:'inventoryassignment',fieldId:'quantity',value: creel_weigh_oh });
create_inv_detail.commitLine('inventoryassignment');log.debug("N","commited inventoryassignment");
newcase_inv_Adj.commitLine({sublistId:'inventory'});log.debug("N","commited inventory");
var invAdjID = newcase_inv_Adj.save();log.debug("N","invAdjID : "+invAdjID);
But, I am getting this error as {"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR"
Is it because of Map/Reduce script?
I don't find anything wrong in the code.
Few suggestions:
- Follow the sequence: Set subsidiary value before you setvalue for account or any other mandatory field.
- First try with inventory items without serial numbers and see if you continue to face same problem.
- You need to make sure you all your variables has valid value (not null or undefined).
- First try doing this in a schedule script.

Store Data from Postman request in variables to use in tests

Im currently trying to get used to POSTMAN and i was wondering if there is a way to store variables from my request JSON Body via Pre Request in some environment variable so ican resuse it in the tests for response value cheks
This is how my json File might look like
{
"text" : "myText",
"attachments": {
"text": "myText2",
"anotherText" : "myText3"
}
So i want to get all Values, store them in a variable before sending my request, and then test if they match the expected value in my response
(example: myText2 gets mapped to green, myText3 gets mapped to red and so on)
That would make it possible to write one test for several request
Thanks a lot!
You can write the following in your script:
let body = JSON.parse(pm.request.body);
_.forEach(body, (value, key) => pm.environment.set(key, JSON.stringify(value)));
This will set each key and it's associated value as an environment variables.
Note you'll need to JSON.parse the value in the test script before using it for testing.
For eg in your test script you'll need to do something like this:
let attachments = JSON.parse(pm.environment.get('attachments'));
pm.test('All attachments are of correct value', function () {
// ...write your test here using the `attachments` variable
});

How to read entire test data file in postman as part of pre-request script?

I am trying to read the entire test data file as a part of pre-request script in postman.
I tried the variable pm.iterationData, however ,it prints only the current iteration data set in the colletion runner.
I need the entire test data and load it as an environment variable in postman.
Is there a way?
The solution that i could find for this is, to set the test data in a variable as a part of pre-request script as follows:
let testdataset =
[
{
"name": "xyz",
"address": "abcd",
"value": "Hello"
},
{
"name" : "mno",
"address" : "defg",
"value" : "Mnop"
}
];
The best way I have come up with dealing with this (collecting all data from a file to us in one request) is to:
Have 2 nodes
The first node has
A dummy call to something like https://postman-echo.com/
Code that:
i. stores the table headers in an environment variable;
ii. concatenates the rows into environment variables;
iii. does 'postman.setNextRequest(null)' for all but the last row
The second node
Only runs in the last iteration
Sends collected data in the environment variable to the API
There is (currently) no way to not make any call on the first node at the moment.
See Github ticket for a request to do this: Request a way for nodes in collection to be logic-only, no request issued #5707