Array object assertion without knowing it's position in Karate Framework - api

I am adding user into array using post call and I want to make assertion but I don't know the position of the object I added into the Array and also there is duplicate entry of the user so how can I assert the user which I recently added into array.
{
"message": {
"users": [
{
"name": "Ashish Patil",
"weight": "65"
},
{
"name": "Ashish Patil",
"weight": "65"
}
]
}
}
this is the example so how I get to know which user added recently.

Related

How to update the status on a Jira issue vis Jira Rest Api

I want to change the status of the project issue on Jira. The status is Open and I want to make it Fixed. My url is PUT https://jiradbg-sandbox.deutsche-boerse.de/rest/api/latest/issue/PID-XX
{
"update": {
"fields":{
"status": [
{
"set": "Fixed"
}
]
}
}
}
and the response is:
{
"errorMessages": ["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream#5de98556; line: 3, column: 9]
(through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]
}
There are two problems that you are encountering here.
The first problem is update or fields should be provided separately to Jira's edit issue API, not one inside of the other. They have equivalent functionality so normally only one is used. For example to update the summary field provide either update:
{
"update": {
"summary": [
{
"set": "Updated by update"
}
]
}
}
or fields:
{
"fields": {
"summary": "Summary set by fields"
}
}
However the status field is a special case and can't be updated directly, which is the second problem here. Changing a status in Jira is called a transition. You need to trigger the transition to move the issue into the status you want.
Start by identifying the available transitions by calling the get transitions API:
GET https://example.net/rest/api/latest/issue/PID-XX/transitions
This tells you which transitions are currently available, something like this:
{
"expand": "transitions",
"transitions": [
{
"id": "21",
"name": "Fixed",
"to": {
"self": "https://example.net/rest/api/2/status/10001",
"description": "",
"iconUrl": "https://example.net/images/icons/status_generic.gif",
"name": "Fixed",
"id": "10001",
"statusCategory": {
"self": "https://example.net/rest/api/2/statuscategory/3",
"id": 3,
"key": "done",
"colorName": "green",
"name": "Done"
}
}
}
]
}
Take the id of the transition you want, in this case 21, then post it to the issue transition API:
POST https://example.net/rest/api/latest/issue/PID-XX/transitions
Use a request body like this:
{
"transition": {
"id": 21
}
}
You should get a 204 HTTP response from Jira which indicates the transition was successful.

PUT inventory custom fragment

This is my device inventory with the custom tasks array:
{
...
"c8y_IsDevice": {},
"tasks": [
{
"task_status" : "NEW",
"task_id" : "1",
"task_data" : {
...
}
},
{
"task_status" : "DONE",
"task_id" : "2",
"task_data" : {
...
}
},
...
]
...
}
I want to create a MQTT/SMARTREST PUT template to update a task by id and status.
For example: 800,[task_id],[task_status]
I am not able to find a way for this, especially it's an json array and all my attempts end up in overwriting the complete json array.
Maybe there's sth. like a condition, if task_id = x -> set task_status = y
Thank you.
You can only replace the whole fragment. There is no way to partially modify fragments.
one way to do it is get the whole array, using it for create a new one locally with the changes to want to do and finally put it again into the database. It is not a kind of solution but have been working for me.
Thanks for the info, but I still got a question about updating an array.
Concerning your answers I want to update the whole fragment.
This is my inventory:
"tasks": [
{
"address": {
"street": "Street",
"street_number": "1"
},
"description": "Test Description",
"id": "1",
"status": "NEW"
},
{
"address": {
"street": "Street2",
"street_number": "2"
},
"description": "Test Description 2",
"id": "2",
"status": "DONE"
}
]
My template:
801,<$.tasks.status>,<$.tasks.description>,<$.tasks.address.street>,<$.tasks.address.street_number>
Template screenshot
Now I publish:
//801,SERIAL,status,description,street_name,street_nr
801,SERIAL,NEW,1,2,3,4
Of course, this will overwrite the array and just set a json object tasks.
"tasks": {
"address": {
"street": "2",
"street_number": "3"
},
"description": "1",
"status": "NEW"
}
So I tried tasks[*]/tasks[] in my template (like in response templates), but this won't work too. I don't get it, maybe you can give me a small solution about putting a complete fragment with an array inside.

Update Account (PUT) Endpoint in new Yodlee API for MFA

Background
I am using the newer Yodlee Aggregation API that differs from what I was previously building off of.
I am currently using this endpoint in the account registration flow to put the MFA response:
PUT /{cobrandName}/v1/providers/{providerAccountId}
My request looks like this:
{
url: `${this.rest}providers/${providerAccountId}`,
headers: {
'Authorization': `cobSession=${self.appToken}, userSession=${token}`
},
form: {
'MFAChallenge': JSON.stringify(newMfa)
}
}
where this.rest is my personal rest url, providerAccountId is the appropriate providerAccountId for the refresh, self.appToken is the current cobrand session token, token is the current user's login token, and newMfa is a JSON object being stringified that matches this profile:
{
"loginForm": {
"mfaTimeout": 94650,
"formType": "questionAndAnswer",
"row": [
{
"id": "SQandA--QUESTION_1--Row--1",
"fieldRowChoice": "0001",
"form": "0001",
"label": "What is the name of your state?",
"field": [
{
"id": "SQandA_QUESTION_1_1",
"name": "QUESTION_1",
"isOptional": false,
"value": "Enter the answer",
"valueEditable": true,
"type": "text"
}
]
},
{
"id": "SQandA--QUESTION_2--Row--2",
"fieldRowChoice": "0001",
"form": "0001",
"label": "What is the name of your first school",
"field": [
{
"id": "SQandA_QUESTION_2_2",
"name": "QUESTION_2",
"isOptional": false,
"value": "Enter the answer",
"valueEditable": true,
"type": "text"
}
]
}
]
}
with the exeption being the value fields of the field object, which have been encrypted with PKI as per instructions.
Issue
However, when I carry out this PUT request, I get this error from Yodlee:
{ errorCode: 'Y803',
errorMessage: 'MFAChallenge or providerParam required',
referenceCode: 'p1460412835654A4Q24t' }
though I clearly have an MFAChallenge parameter in my form. Any ideas on why I could be getting this error if the MFAChallenge is present (and note that it is the only info that is passed through the PUT request other than through headers or url parameters)? I tried putting it through as body data, but that doesn't seem to work, and very few of the API endpoints actually seem to use body over form encoded strings, though there was at least one.
You have to send this information MFAChallenge as part of URL, see below example
https://developer.api.yodlee.com/ysl/restserver/v1/providers/10114184?MFAChallenge=%7B%20%22loginForm%22%3A%20%7B%20%20%20%20%20%22mfaTimeout%22%3A%2094650%2C%20%20%20%20%20%22formType%22%3A%20%22questionAndAnswer%22%2C%20%20%20%20%20%22row%22%3A%20%5B%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA--QUESTION_1--Row--1%22%2C%20%20%20%20%20%20%20%20%20%22fieldRowChoice%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22form%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22label%22%3A%20%22What%20is%20the%20name%20of%20your%20state%3F%22%2C%20%20%20%20%20%20%20%20%20%22field%22%3A%20%5B%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA_QUESTION_1_1%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22QUESTION_1%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isOptional%22%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Enter%20the%20answer%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22valueEditable%22%3A%20true%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22text%22%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%20%20%20%20%20%20%20%5D%20%20%20%20%20%7D%2C%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA--QUESTION_2--Row--2%22%2C%20%20%20%20%20%20%20%20%20%22fieldRowChoice%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22form%22%3A%20%220001%22%2C%20%20%20%20%20%20%20%20%20%22label%22%3A%20%22What%20is%20the%20name%20of%20your%20first%20school%22%2C%20%20%20%20%20%20%20%20%20%22field%22%3A%20%5B%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22id%22%3A%20%22SQandA_QUESTION_2_2%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22QUESTION_2%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isOptional%22%3A%20false%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%20%22Enter%20the%20answer%22%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22valueEditable%22%3A%20true%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22text%22%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%20%20%20%20%20%20%20%5D%20%20%20%20%20%7D%20%5D%20%7D

Using the advanced query api and get all pages back

I can successfully call into an advanced query method and get the first page of data back (using the post option) refernced in http://api.docs.import.io/#QueryMethods
Anyone have an idea how to page after that? I get 20 out of 190 results. My query looks like:
var query = {
"input": { "last_name": name },
"additionalInput": {
"8d817939-my-api-key-9502ed72": cookie
},
"returnPaginationSuggestions": true
}
Where param name and cookie are known vars.
The results do not return a pagination block either as in the model result:
{
"connectorVersionGuid": "string",
"pagination": {
"pattern": "string",
"next": "string",
"currentPageNum": 0,
"previous": "string"
},
"connectorGuid": "string",
"totalResults": 0,
"errorType": "TimeoutException",
"outputProperties": [
{
"type": "STRING",
"name": "string"
}
],
"cookies": [
"string"
],
"results": [
{}
],
"pageUrl": "string",
"error": "string",
"data": {}
}
If the response is not returning the "Pagination" block, it means that the system was not able to identify pagination on a given page.
As far as I remember pagination is flaky for Extractor APIs, while it works quite well for Magic APIs. I would recommend trying to get a Magic extractor, and getting pagination suggestions for it. Than you should be able to get the "Pagination" block in your response, and use "next" value to get the URL of the next page.

How to define a boolean field in MongoDB BSON document?

I'm trying to add boolean status field to a document on MongoLabs but I get a syntax error on that particular field when I try to save.
The type specifier seems 8 sees good according to the docs, but I can't find any examples on defining a boolean field within a document.
I managed to pin down the error to the status field, as the document saves without this field added.
Can anyone advise on the correct BSON syntax for the boolean field?
This is the boolean field I've added:
"status": {
{"$type": 8 } : true
}
And the complete document for reference:
{
"_id": {
"$oid": "565c4a37e4b0ed4652848949"
},
"email": "jd#outlook.com",
"products": [
{
"productId": "0121",
"price": 12.5,
"description": "A generic muffin"
},
{
"productId": "0122",
"price": 13.5,
"description": "A generic coffee"
},
{
"productId": "0123",
"price": 14.5,
"description": "A generic tea"
}
],
"date": {
"$date": "2014-03-03T03:45:00.000Z"
},
"status": {
{"$type": 8 } : true
}
}
If you wondering how to define a Boolean in a model class of node.js. If you are using MongoDB.
shopOpenStatus: {
type:Boolean,
default:"false",
required:true
}
It took me 10 min to discover this.
In case anyone else had the same issue. The data stored on MongoLabs is JSON, which is then converted to BSON locally using the driver.
The correct format below is as follows:
{
"status": true
}