Gatling - Extract Json value from previews request - gatling

I'm new in Gatling, and trying to get value from json key.
This check give me labels:
.check(jsonPath("$[1].ppp[1].label").saveAs("label"))
In this request i got all json data like this
[
{
"id":258,
"code":"D00CC3056",
"label":"Test-0"
},
{
"id":260,
"code":"D00RR148",
"label":"Test-1"
}
]
From this Json, i need to get code value from a specific label, to use it in request after.
Something like : get code where label is "Test-1".
I've trying this but doesn't works:
.exec(
http("request_3:GET_/api/code")
.get("/api/code")
.check(status.is(200))
.check(jsonPath("$..[*].code").find("{$label}").saveAs("code"))
)
I don't know how to do this.
Any help ?

With JMESPath that you should really learn and that Gatling supports:
.check(jmesPath("[?label == 'Test-1'].code").saveAs("code"))

Related

Cannot return documents based off a sorted index using Fauna DB

I'm bumbling my way through adding a back-end to my site and have decided to get acquainted with graphQL. I may be structuring things totally the wrong way, however from following some tutorials I have a React front-end (hosted on Vercel), so I have created an api folder in my app to make use of Vercel's serverless functions. I'm using Apollo server and I decided to go with Fauna as my database.
I've successfully been able to return an entire collection via my API. Now I wish to be able to return the collection sorted by my id field.
To do this I created an index which looks like this:
{
name: "sort_by_id",
unique: false,
serialized: true,
source: "my_first_collection",
values: [
{
field: ["data", "id"]
},
{
field: ["ref"]
}
]
}
I then was able to call this via my api and get back and array, which simply contained the ID + ref, rather than the associated documents. I also could only console log it, I assume because the resolver was expecting to be passed an array of objects with the same fields as my typedefs. I understand I need to use the ref in order to look up the documents, and here is where I'm stuck. An index record looks as follows:
[1, Ref(Collection("my_first_collection"), "352434683448919125")]
In my resolvers.js script, I am attempting to receive the documents of my sorted index list. I've tried this:
async users() {
const response = await client.query(
q.Map(
q.Paginate(
q.Match(
q.Index('sort_by_id')
)
),
q.Lambda((ref) => q.Get(ref))
)
)
const res = response.data.map(item => item.data);
return [... res]
}
I'm unsure if the problem is with how I've structured my index, or if it is with my code, I'd appreciate any advice.
It looks like you also asked this question on the Fauna discourse forums and got an answer there: https://forums.fauna.com/t/unable-to-return-a-list-of-documents-via-an-index/3511/2
Your index returns a tuple (just an array in Javascript) of the data.id field and the ref. You confirmed that with your example result
[
/* data.id */ 1,
/* ref */ Ref(Collection("my_first_collection"), "352434683448919125")
]
When you map over those results, you need to Get the Ref. Your query uses q.Lambda((ref) => q.Get(ref)) which passes the whole tuple to Get
Instead, use:
q.Lambda(["id", "ref"], q.Get(q.Var("ref")))
// or with JS arrow function
q.Lambda((id, ref) => q.Get(ref))
or this will work, too
q.Lambda("index_entry", q.Get(q.Select(1, q.Var("index_entry"))))
// or with JS arrow function
q.Lambda((index_entry) => q.Get(q.Select(1, index_entry)))
The point is, only pass the Ref to the Get function.

JSON webhook through WP Automator - Custom Syntax

I have this JSON code:
{
"Subscribers": [
{
"EmailAddress":"yikes#to.com",
"CustomFields": [
],
"Lists": [
200575230
]
}
]
}
I tested it on Postaman, it works - it should push email address of every new registered user to the Campaigner.
But, for automation I use WP automator webhooks in Wordpress. For creation of this automation I can't use this above code, but code formatted per Automator "syntax".
In Automator, for example - this code below:
data": {
"customer": 123,
"first_name": "AutomatorWP",
}
Is mapped like this:
data/customer
data/first_name
And for the brackets - "The brackets ([]) place the information inside an array, so you need to place the array index like “data/0/first_name” to use this “first_name” parameter on tags." - Documentation
Does anyone knows or can figure out how to above first code "translate" to this Automator layout?
I tried with:
Subscriber/EmailAddress and Subscriber/0/EmailAddress - but I can't figure out how to send email to the right list, as simple as it is in clean JSON code
Any help appreciated
I tried any possible variation, always same error: Invalid Payload
I don't have any idea anymore, so maybe somebody worked earlier with this Automator "syntax"

Angular Request how it works for nestjsx/crud

I've been trying for hours to make it work and I can't do it, I hope some of you have the answer to my question because it must be very simple and I am a beginner
I am using AngularJs and NestJs in Nest used the #nestjsx/crud and I went trow the request docs so, here is the problem:
This is my Angular service function
getProductsOfPiece(pieceId: number): Observable<ProductSimple[]> {
return this.http.get<ProductSimple[]>(
'api/producto/', {
params: {
fields: "id,refFabr,refCliente,descrCorta,imagen",
filter: 'pieza.id||$eq||'+ pieceId
}
}
);
}
This request gives me a 400 Bad Request, it looks like this:
/api/producto/?fields=id,refFabr,refCliente,descrCorta,imagen&filter=pieza.id%257C%257C$eq%257C%257C1
I imagine the % and the hexadecimal have something to do with the URI coding and tried to encode/decode it, but didn't work.
I also tried using the class RequestQueryBuilder of #nestjsx/crud-request from the FrontEnd usage referenced in the docs, and append it to the URL
let queryString = RequestQueryBuilder.create()
.select(["id","refFabr","refCliente","descrCorta","imagen"])
.setFilter({
field: "coleccion.id",
operator: CondOperator.EQUALS,
value: collectionId
}).query();
return this.http.get<ProductSimple[]>(
'api/producto/?'+queryString
);
but got worse result
/api/producto/?fields=id%2CrefFabr%2CrefCliente%2CdescrCorta%2Cimagen&filter%5B0%5D=pieza.id%7C%7C%24eq%7C%7C1
What I don't understand is how I do this with my Postmand and it works!
api/producto/?fields=id,refFabr,refCliente,descrCorta,imagen&filter=coleccion.id||$eq||6
How can I make it work, what is wrong with my code?
Finally got the answer, just had to set the .query(false) on the RequestQueryBuilder, this boolean parameter is for encode, seams like Angular's HttpClient class does some encoding or something to the URL so, anyway
It Works! Here is the code:
getProductsOfPiece(pieceId: number): Observable<ProductSimple[]> {
let queryString = RequestQueryBuilder.create()
.select(["id","refFabr","refCliente","descrCorta","imagen"])
.setFilter({
field: "coleccion.id",
operator: CondOperator.EQUALS,
value: collectionId
}).query(false);
return this.http.get<ProductSimple[]>(
'api/producto/?'+queryString
);
}
And you need to import
RequestQueryBuilder of #nestjsx/crud-request
npm i #nestjsx/crud-request.
Any observations are welcome...
UPDATE
To create or update
Here are de docs
Create One https://github.com/nestjsx/crud/wiki/Controllers#create-one-resource
Update One https://github.com/nestjsx/crud/wiki/Controllers#update-one-resource
Following that guide the create and update are simple
Just do POST to the API 'api/producto/' (for example) with the object as body in the request
For the Update follows similar just using the PUT method and the API with the model id 'api/producto/1' (for example)

How to handle null or Non required column in json in Azure Logic App

sample api url: https://jsonplaceholder.typicode.com/posts
title is not a mandatory field in received json. It may or may not be part of each record.
When this field is missing in record, #{items('For_each')['title']} this throws an exception.
I want the value of myVariable to set as 'N/A' in that case. How do i do this?
I make the assumption that this is an array and that you have a set schema in the HTTP trigger. If the schema is set, make sure you remove Title as a required field.
Using these asumptions you should be able to do the following with Coalesce()
If Title now is not present in the body of the HTTP request the Title will be equal to 'N/A'
Using postman to test, note, the result is backward as it is the first object sent in my array.
Cause you url data all have the title, so I test with When a HTTP request is recived trigger to get the json data.
In this situation the data could only be like this:
{
"userId": 1,
"id": 2,
"body": "xxxxx"
}
not like the below one:
{
"userId": 1,
"id": 2,
"title":,
"body": "xxxxxxxxx"
}
I test with the first one, it did show the error message: property 'title' doesn't exist,. So here is my solution, after the action Set variable, add an action to set the variable you want and set the action run after Set variable has failed like the below picture.
After configuration, if the title doesn't exist, it will be set as N/A as you want.
Hope this could help you, if this is not what you want or you have other questions, please let me know.

Append new JSON objects to an array in Polymer

I am using a REST API to fetch an array of objects in a Polymer 2.0.2 project. The response is something like this:
[
{"name":"John","city":"Mumbai"},
{"name":"Ron","city":"New York"},
{"name":"Harry","city":"Lisbon"}
]
When the response is received, I set my property named content as follows:
_contentAjaxResponseHandler(event) {
this.set('content', event.detail.response);
}
This works as long as the REST API is called once.
Now, I want to fetch the next batch when user scrolls to the bottom of the page and add it to the existing data.
So, my question is, what is the best way to append new result to the existing content array? Or in other words, What is the best way to merge 2 arrays in polymer?
Till now, the only way I can think of is to loop over the new result and call push method.Something like this:
_contentAjaxResponseHandler(event) {
let newResponse = event.detail.response;
newResponse.forEach(function(newObj){
this.push('content',newObj);
});
}
The following code worked for me:
_contentAjaxResponseHandler(event) {
let newResponse = event.detail.response;
this.set('content',this.content.concat(newResponse));
}

Resources