I'm using Gatling tool to load test my service.
I have following response from my server(just an example):
{
"result: {
"288249": {
"allowEdit": 1,
"cells": [
{
"rollupId": "288249",
"description": "Gatling description: 93"
},
{
"rollupId": "288249",
"description": "Gatling description: 83"
}
]
}
}
}
What I need is loop thought all $.result.288249.cells[*].description fields and verify that there's a value, which is equal to what I have in one of my session objects.
It should look similar to following pseudo code:
.check(
jsonPath("$.result.*.cells[*].description").contains("${mySessionValue})
)
Is there are method, which I can use in similar way ?
Thanks in advance!
I think, I've found the solution
.check(
jsonPath("$.result.*.cells[?(#.description == '${mySessionValue}')]")
.find
.exists
)
This should do the work.
You can loop thru as follows
$.each($.result, function(index,obj){
$.each(obj['cells'], function(innerInd, innerObj){
if( ${mySessionValue} == innerObj['description'] )
{
console.log('Found')
return
}
})
})
Related
I'm new to ELK, can i use 2 conditions in Elastic watchers. I am getting a field from logs like data = 0 and data = 1 so i need to use that "data" as condition inside my watcher to elobarate the events.
Thanks in advance
There's many solutions. Here's one using painless script:
[query sections...]
},
"condition": {
"script": {
"source": """
def obj = ctx.payload.hits.hits.0;
if (obj.data.value == 0 || obj.data.value == 1) {
return true;
}
return false;
""",
"lang": "painless"
}
},
"actions": {
[actions sections to follow...]
Of course I'm only making up the CTX context data path. In the example, I am referring to the "data" field of the first returned record. You will have to figure out what you want to check. One common piece of data is from aggregations, then you will have a to access ctx.payload.aggregations.*
I am using graphlient gem to make a graphql query call
I have to make this call in controller so thats why I am using graphlient ta make call
client = Graphlient::Client.new("http://localhost:3000/graphql", headers: {
'Authorization': "API #{api_key}"
})
response = client.query do
query{
search(id: 1){
edges{
node{
id
name
timing{
start
end
}
}
}
}
end
I have timing field which has two attribute start and end but Rails is giving me syntax error as
end is a keyword in Rails
How can I run this query without syntax error? Is there any way to send the query in string format to run this?
I am assuming that you are using ashkan18/graphlient since this is the first result when searching for graphlient.
And according to its documentation, you can use a string for making queries. So instead of using blocks in your example, you can do this instead:
response = client.query <<~GRAPHQL
query {
search(id: 1) {
edges {
node {
id
name
timing {
start
end
}
}
}
}
}
GRAPHQL
We are creating a Zapier app to expose our APIs to the public, so anyone can use it. The main endpoint that people are using returns a very large and complex JSON object. Zapier, it looks like, has a really difficult time parsing nested complex JSON. But it does wonderful with a very simple response object such as
{ "field": "value" }
Our data that is being returned has this structure and we want to move some of the fields to the root of the response so it's easily parsed by Zapier.
"networkSections": [
{
"identifier": "Deductible",
"label": "Deductible",
"inNetworkParameters": [
{
"key": "Annual",
"value": " 600.00",
"message": null,
"otherInfo": null
},
{
"key": "Remaining",
"value": " 600.00",
"message": null,
"otherInfo": null
}
],
"outNetworkParameters": null
},
So, can we do something to return for example the remaining deductible?
I got this far (adding outputFields) but this returns an array of values. I'm not sure how to parse through this array either in the Zap or in the App.
{key: 'networkSections[]inNetworkParameters[]key', label: 'xNetworkSectionsKey',type: 'string'},
ie this returns an array of "Annual", "Remaining", etc
Great question. In this case, there's a lot going on, and outputFields can't quite handle it all. :(
In your example, inNetworkParameters contains an array of objects. Throughout our documentation, we refer to these as line items. These lines items can be passed to other actions, but the different expected structures presents a bit of a problem. The way we've handled this is by letting users map line-items from one step's output to another step's input per field. So if step 1 returns
{
"some_array": [
{
"some_key": "some_value"
}
]
}
and the next step needs to send
{
"data": [
{
"some_other_key": "some_value"
}
]
}
users can accomplish that by mapping some_array.some_key to data.some_other_key.
All of that being said, if you want to always return a Remaining Deductible object, you'll have to do it by modifying the result object itself. As long as this data is always in that same order, you can do something akin to
var data = z.JSON.parse(bundle.response.content);
data["Remaining Deductible"] = data.networkSections[0].inNetworkParameters[1].value;
return data;
If the order differs, you'll have to implement some sort of search to find the objects you'd like to return.
I hope that all helps!
Caleb got me where I wanted to go. For completeness this is the solution.
In the creates directory I have a js file for the actual call. The perform part is below.
perform: (z, bundle) => {
const promise = z.request({
url: 'https://api.example.com/API/Example/' + bundle.inputData.elgRequestID,
method: 'GET',
headers: {
'content-type': 'application/json',
}
});
return promise.then(function(result) {
var data = JSON.parse(result.content);
for (var i=0; i<data.networkSections.length; i++) {
for (var j=0; j<data.networkSections[i].inNetworkParameters.length; j++) {
// DEDUCT
if (data.networkSections[i].identifier == "Deductible" &&
data.networkSections[i].inNetworkParameters[j].key == "Annual")
data["zAnnual Deductible"] = data.networkSections[i].inNetworkParameters[j].value;
} // inner for
} // outer for
return data;
});
When I use the following query, I get a good response (with only the first 5 days of May, so apparently the default is not 'This Fiscal Year-to-date' as the documentation suggests, but I digress):
https://quickbooks.api.intuit.com/v3/company/0123456789/reports/CustomerSales
When I add parameters, I get an oauth exception. For example:
https://quickbooks.api.intuit.com/v3/company/0123456789/reports/CustomerSales?start_date='2013-01-01'&end_date='2014-05-06'
Gives me this:
{
"Fault": {
"type": "AUTHENTICATION",
"Error": [
{
"Message": "message=Exception authenticating OAuth; errorCode=003200; statusCode=401",
"code": "3200"
}
]
},
"requestId": "[redacted]",
"time": "[redacted]"
}
This gives me the same result:
https://quickbooks.api.intuit.com/v3/company/0123456789/reports/CustomerSales?date_macro='This Fiscal Year'
So does this:
https://quickbooks.api.intuit.com/v3/company/148305798/reports/CustomerSales?accounting_method='Accrual'
I figure I'm missing something small. I'm not changing any of the headers or any of the other request details...just the url.
I tried without the single quotes around the dates and other params too.
What am I breaking?
Are you including the data to the right of the ? in the URL in the "base" string and are you sorting it with the other parameters?
I've tried this report using java devkit.
It worked fine for me. PFB details.
Request URI - https://quickbooks.api.intuit.com/v3/company/1092175540/reports/CustomerSales?accounting_method=Accrual&start_date=2014-01-01&requestid=61234ddb7e14ce2a5fe4e2f0318b31c&minorversion=1&
My test company file is empty.. That's why got the following JSON response.
{
"Header":{
"Time":"2014-05-06T20:42:08.783-07:00",
"ReportName":"CustomerSales",
"ReportBasis":"Accrual",
"StartPeriod":"2014-05-01",
"EndPeriod":"2014-05-06",
"SummarizeColumnsBy":"Total",
"Currency":"USD"
},
"Columns":{
"Column":[
{
"ColTitle":"",
"ColType":"Customer"
}
]
},
"Rows":{
"Row":[
{
"ColData":[
{
"value":"TOTAL"
}
],
"group":"GrandTotal"
}
]
}
}
JAVA code
void testCustomerSalesReport(Context context) {
Config.setProperty(Config.SERIALIZATION_RESPONSE_FORMAT, "json");
ReportService service = new ReportService(context);
service.setStart_date("2014-01-01");
service.setAccounting_method("Accrual");
Report report = null;
try {
report = service.executeReport(ReportName.CUSTOMERSALES.toString());
} catch (FMSException e) {
e.printStackTrace();
}
}
API Doc Ref - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/reports/customersales
Hope it will be useful.
Thanks
I'm having trouble creating the following JSON using uisng the C# MVC3 system.web.helpers.json namespace. Here is what I am trying to form:
{"success":true,"msg":"", "Data": [ { "Id":167 } ] }
What I have tried is this (with no success)
var x = Json(
new {Id = result.SponsorListId});
return Json(new
{
success,
msg = success ? "" : "sponsorListResult Passed Into Update as null",
Data = new List<Json>() {x}
}, JsonRequestBehavior.DenyGet);
I've tried lots of other things also, but no point in listing all my failures.
Thanks for any help on this.
Basically all the Json() method does is serialize the object you send it. When you send it a List you are sending it a JsonResponse which isn't what you are intending. What you should do is:
return Json(new
{
success,
msg = success ? "" : "sponsorListResult Passed Into Update as null",
Data = new []{ new { Id: result.SponsorListId } }
}, JsonRequestBehavior.DenyGet);
Which should serialize out to where you want it to be.