Dynamic values in Rest API using JMeter - api

I have payload POST call:
{
"tenantName":"loki",
"owner":
{
"country": "india",
"firstName": "raj",
"lastName": "kumar",
"locale": "in",
"organization": "softwareag",
"phone": "9789155778",
"title": "mr",
"userName": "raraj#softwareag.com",
"email": "raraj#softwareag.com",
"password":"V2VsY29tZUAxMjM0"
},
"products": [
"cumulocity",
"b2b"
]
}
In that payload, the tenant name is unique, How to pass different values for each post call?

You can use __RandomString to randomize name, for example 5 lower case letters:
${__RandomString(5,abcdefghijklmnopqrstuvwxyz,)}
RandomString function returns a random String of length using characters in chars to use
Or load name values from CSV Data set config

You can use __groovy() function in order to call RandomStringUtils.randomAlphabetic() method like:
${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}
replace 4 with the number of your choice to make the random string shorter or longer
The function can be inlined directly into your request body
{
"tenantName": "${__groovy(org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(4),)}",
"owner": {
"country": "india",
"firstName": "raj",
"lastName": "kumar",
"locale": "in",
"organization": "softwareag",
"phone": "9789155778",
"title": "mr",
"userName": "raraj#softwareag.com",
"email": "raraj#softwareag.com",
"password": "V2VsY29tZUAxMjM0"
},
"products": [
"cumulocity",
"b2b"
]
}
More information: Apache Groovy - Why and How You Should Use It

Related

Get the value from the response based on a condition and store it to a variable

I would like to get the value from the response based on a condition and store it to a variable.
In the below JSON, I would like to store the value when the name matches to something I prefer. Is there a way to achieve this using Karate API?
{
"results": [
{
"name": "Sample1",
"email": "sample1#text.com",
"id": "U-123"
},
{
"name": "Sample2",
"email": "sample2#text.com",
"id": "U-456"
},
{
"name": "Sample3",
"email": "sample3#text.com",
"id": "U-789"
}
]
}
So after reading the comment, my interpretation is to "find" the id where name is Sample2. Easy, just use a filter() operation, refer the docs: https://github.com/karatelabs/karate#jsonpath-filters
Instead of using a filter, I'm using the JS Array find() method as a very concise example below:
* def response =
"""
{ "results": [
{ "name": "Sample1", "email": "sample1#text.com", "id": "U-123" },
{ "name": "Sample2", "email": "sample2#text.com", "id": "U-456" },
{ "name": "Sample3", "email": "sample3#text.com", "id": "U-789" }
]
}
"""
* def id = response.results.find(x => x.name == 'Sample2').id
* match id == 'U-456'
Take some time to understand how it works. Talk to someone who knows JS if needed.

Get all API fields definitions from Podio application

Responses from Podio API returns an JSON array of items with a fields property. Each field carries its values and its config.
For example a category field for the Gender:
{
"type": "category",
"field_id": 219922852,
"label": "Gender",
"values": [
{
"value": {
"status": "active",
"text": "Prefer not to say",
"id": 3,
"color": "F7F0C5"
}
}
],
"config": {
"settings": {
"multiple": true,
"options": [
{
"status": "active",
"text": "Male",
"id": 1,
"color": "DCEBD8"
},
{
"status": "active",
"text": "Female",
"id": 2,
"color": "F7F0C5"
},
{
"status": "active",
"text": "Prefer not to say",
"id": 3,
"color": "F7F0C5"
}
],
"display": "inline"
},
"mapping": null,
"label": "Gender"
},
"external_id": "gender"
},
How can I fetch the config without having to query a specific item?
Is there a way to get every field in the response? Because if the queried item does not have a field value set, Podio doesn't return it in the response.
I would like to get the field config for ALL the fields. If possible, with a single API request. In particular I am interested in all the possible values (in case of Category or Relationship fields) so that I could match them with local values I have.
This way I can use the field structure to programmatically map some local values to the format required by the Podio API; and then generate a fields payload that to update/create Podio items via an API calls.
You can request the Podio Get App method to get the app configuration.
Podio Doc Ref: https://developers.podio.com/doc/applications/get-app-22349

How to select column with json without sending column name?

I'm setting up an API with Node and postgreSQL-node (pg), and when I query for the column in my data base that contains JSON it returns an array of objects with the columns name and the json I want to access.
My current query is:
select jsondata
from breweries
The output is:
[
{
"jsondata": {
"id": 2,
"name": "Avondale Brewing Co",
"brewery_type": "micro",
"street": "201 41st St S",
"city": "Birmingham",
"state": "Alabama",
"postal_code": "35222-1932",
"country": "United States",
"longitude": "-86.774322",
"latitude": "33.524521",
"phone": "2057775456",
"website_url": "http://www.avondalebrewing.com",
"updated_at": "2018-08-23T23:19:57.825Z",
"tag_list": []
}
},
{"jsondata": {...}},
{...}
]
My expectation is to get and array with the contents inside "jsondata" without the name of the column "jsondata", but I can't find a way to access it one level in my query.
Edit:
Here is what I expect:
[
{
"id": 2,
"name": "Avondale Brewing Co",
"brewery_type": "micro",
"street": "201 41st St S",
"city": "Birmingham",
"state": "Alabama",
"postal_code": "35222-1932",
"country": "United States",
"longitude": "-86.774322",
"latitude": "33.524521",
"phone": "2057775456",
"website_url": "http://www.avondalebrewing.com",
"updated_at": "2018-08-23T23:19:57.825Z",
"tag_list": []
},
{...},
{...}
]
I'm not sure what exact output you're expecting, but you can convert the array of dictionaries to rows and then return the jsondata values as individual rows using this:
SELECT jsonb_array_elements(jsondata)->'jsondata'
FROM breweries
Is that along the lines of what you want?
SQL Fiddle

Remove email and phone number from customer in Kustomer

I'm having trouble deleting the emails and phones keys from customers.
When I have to re-create a customer, I get an error message because the first record has the same phone and email address. I tried simply removing them from the old record but it gives me a 400 bad request. It says I need to specify an email and phone.
This wouldn't be surprising, especially since the documentation specifies that they are required fields. What's strange is that I can create customers without emails and phones just fine. It's just that once they have them, I can't get rid of them. Is there some workaround that would allow me to re-create a customer?
The way to currently remove an email or phone number from a customer is to update the customer object with the emails you want to keep.
For an example, if you have a customer object that looks like:
{
"data": {
"type": "customer",
"id": "58863fe94aa1701100efcb1d",
"attributes": {
"name": "Joe Cornelius Schmoe III",
"displayName": "Joe Cornelius Schmoe III",
"displayColor": "teal",
"displayIcon": "broom",
"externalId": "user-3",
"externalIds": [
{
"externalId": "user-3",
"verified": true
}
],
"firstName": "Joe",
"lastName": "Schmoe",
"sharedExternalIds": [],
"emails": [
{
"email": "test#gmail.com",
"verified": false,
"type": "home"
},
{
"email": "test2#gmail.com",
"verified": false,
"type": "home"
}
],
....
}
In cases where you would like to remove the email associated with home (works the same way for phones array.)
PUT /v1/customers/{customerId}
{
"emails": [
{
"email": "test#gmail.com",
"verified": false,
"type": "home"
}
]
}
The customer record will now be updated to only include the specified email.
{
"data": {
"type": "customer",
"id": "58863fe94aa1701100efcb1d",
"attributes": {
"name": "Joe Cornelius Schmoe III",
"displayName": "Joe Cornelius Schmoe III",
"displayColor": "teal",
"displayIcon": "broom",
"externalId": "user-3",
"externalIds": [
{
"externalId": "user-3",
"verified": true,
"id": null
}
],
"firstName": "Joe",
"lastName": "Schmoe",
"sharedExternalIds": [],
"emails": [
{
"email": "test#gmail.com",
"verified": false,
"type": "home",
"id": null
}
]
.....
}

Read Specific Character from NSSTRING and save them in NSDictionary (LinkedIn Api)

I am using Linkedin Api in my Iphone App.I want to read the Connection Names and their Profession.In First Step I read the user name and Professional by using the Following Api.
http://api.linkedin.com/v1/people/~
It return the following String and I convert that string in to NSDictionary .Its Work Fine.
====================================
coming string is equql to {
"headline": "Computer Software Professional",
"lastName": "Ahmed",
"siteStandardProfileRequest": {"url": "http://www.linkedin.com/profile?viewProfile=&key=86794265&authToken=ZBFd&authType=name&trk=api*a135617*s143990*"},
"firstName": "Umair"
}
========================================
Nsstring to NSDictionary conversion:-
Data coming from LinkedIn site
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(#"coming string is equql to %#",responseBody);
NSDictionary *profile = [responseBody objectFromJSONString];
[responseBody release];
if ( profile )
{
name.text = [[NSString alloc] initWithFormat:#"%# %#",
[profile objectForKey:#"firstName"], [profile objectForKey:#"lastName"]];
headline.text = [profile objectForKey:#"headline"];
}
The Above code Work Fine.
But when i use Connection Api.(For Linkedin Friends)
http://api.linkedin.com/v1/people/~/connections
I receive the following response in String.
========================================================================================
coming string is equql to {
"values": [
{
"headline": "--",
"id": "jrzlnzmKgH",
"lastName": "ahmad",
"pictureUrl": "http://media.linkedin.com/mpr/mprx/0_7bH7Ex4_zD3EJFYkDFRKEjehBacbMF0kD8prEjV0eIiBQ_HXiT4_XgmAM8BZVhOemkol5sXLbyGk",
"location": {
"name": "United Arab Emirates",
"country": {"code": "ae"}
},
"siteStandardProfileRequest": {"url": "http://www.linkedin.com/profile?viewProfile=&key=87979190&authToken=RO5n&authType=name&trk=api*a135617*s143990*"},
"apiStandardProfileRequest": {
"headers": {
"values": [{
"name": "x-li-auth-token",
"value": "name:RO5n"
}],
"_total": 1
},
"url": "http://api.linkedin.com/v1/people/jrzlnzmKgH"
},
"firstName": "junaid"
},
{
"headline": "Field Testing Engineer at SENSYS",
"id": "iZbYn6whQT",
"lastName": "Ali Ayub",
"location": {
"name": "Pakistan",
"country": {"code": "pk"}
},
"siteStandardProfileRequest": {"url": "http://www.linkedin.com/profile?viewProfile=&key=66010848&authToken=k_Wj&authType=name&trk=api*a135617*s143990*"},
"apiStandardProfileRequest": {
"headers": {
"values": [{
"name": "x-li-auth-token",
"value": "name:k_Wj"
}],
"_total": 1
},
"url": "http://api.linkedin.com/v1/people/iZbYn6whQT"
},
"industry": "Government Administration",
"firstName": "Prince"
},
{
"headline": "Student at comsats",
"id": "AZtfwY31D2",
"lastName": "Anwar",
"location": {
"name": "Pakistan",
"country": {"code": "pk"}
},
"siteStandardProfileRequest": {"url": "http://www.linkedin.com/profile?viewProfile=&key=106573059&authToken=4_ll&authType=name&trk=api*a135617*s143990*"},
"apiStandardProfileRequest": {
"headers": {
"values": [{
"name": "x-li-auth-token",
"value": "name:4_ll"
}],
"_total": 1
},
"url": "http://api.linkedin.com/v1/people/AZtfwY31D2"
},
"industry": "Computer Networking",
"firstName": "Irfan"
},
{
"headline": "WiMAX RF Planning Engineer at IACGRP",
"id": "ERjOSiKbPo",
"lastName": "Arsil",
"pictureUrl": "http://media.linkedin.com/mpr/mprx/0_T_Ic9x0GWkhvZ7R13LHX9juCdb-ZsoI1iC0e9pDY9C6e5mpPD5RRZyMKFdtbJDo088ddJU1s5_py",
"location": {
"name": "Pakistan",
"country": {"code": "pk"}
},
"siteStandardProfileRequest": {"url": "http://www.linkedin.com/profile?viewProfile=&key=35285050&authToken=ouYS&authType=name&trk=api*a135617*s143990*"},
"apiStandardProfileRequest": {
"headers": {
"values": [{
"name": "x-li-auth-token",
"value": "name:ouYS"
}],
"_total": 1
},
"url": "http://api.linkedin.com/v1/people/ERjOSiKbPo"
},
=====================================================
Now I want to convert it in to NsDictionary With key Value Like Firstname,Lastname etc.How can I do This.
Thanks in Advance
You need to use a JSON library for iPhone. One of them is the TouchJSON library, you can see this question to learn more.
Use Json Libraray for Retreive your Values.Its so Simple.Thanks