here is my API get request:
{
"data": [
{
"id": 2,
"attributes": {
"title": "something",
"game": "default",
"players": "static",
}
}
],
}
I would like to set "Players" to an array like below:
"attributes": {
"title": "23123",
"game": "1231",
"players": [
"1" : "static1",
"2" : "static2",
"3" : static3",
],
}
how can i make this array?
You need to make a component called "Player" from content-type builder and then add this component with repeatable to your main entity type.
Related
This is my api response. Want to extract the value of the Id based on the displayNumber. This display number is a given in the list of values in examples/csv file.
{
"Acc": [
{
"Id": "2b765368696b3441673633325",
"code": "SGD",
"val": 406030.83,
"displayNumber": "8957",
"curval": 406030.83
},
{
"Id": "4e676269685a73787472355776764b50717a4",
"code": "GBP",
"val": 22.68,
"displayNumber": "1881",
"curval": 22.68
},
{
"Id": "526e666d65366e67626244626e6266467",
"code": "SGD",
"val": 38404.44,
"displayNumber": "1004",
"curval": 38404.44
},
],
"combinations": [
{
"displayNumber": "3444",
"Code": "SGD",
"Ids": [
{
"Id": "2b765368696b34416736333254462"
},
{
"Id": "4e676269685a7378747235577"
},
{
"Id": "526e666d65366e6762624d"
}
],
"destId": "3678434b643530456962435272d",
"curval": 3.85
},
{
"displayNumber": "8957",
"code": "SGD",
"Ids": [
{
"Id": "3678434b6435304569624357"
},
{
"Id": "4e676269685a73787472355776764b50717a4"
},
{
"Id": "526e666d65366e67626244626e62664679"
}
],
"destId": "2b765368696b344167363332544",
"curval": 406030.83
},
{
"displayNumber": "1881",
"code": "GBP",
"Ids": [
{
"Id": "3678434b643530456962435275"
},
{
"Id": "2b765368696b3441673"
},
{
"Id": "526e666d65366e67626244626e626"
}
],
"destId": "4e676269685a7378747d",
"curval": 22.68
},
]
}
Examples
|displayNumber|
|8957|
|3498|
|4943|
Below expression works if i give the value
* def tempid = response
* def fromAccount = get[0] tempid.Acc[?(#.displayNumber==8957].Id
I'm not sure how to make this comparison value (i.e. 1881) as a variable which can be read from examples (scenario outline) or a csv file. Went through the documentation, which recommends, karate filters or maps. However, not able to follow how to implement.
You almost got it :-). This is the way you want to solve this
Scenario Outline: Testing SO question for Navneeth
* def tempid = response
* def fromAccount = get[0] tempid.Acc[?(#.displayNumber == <displayNumber>)]
* print fromAccount
Examples:
|displayNumber|
|8957|
|1881|
|3444|
You need to pass the placeholder in examples as -
'<displayNumber>'
i have json file with this data
[
{
“rolename”: “Number one”,
“roledescription”: “Number one”,
“rolepermission”: [“manage_users”,“view_user_logs”],
“roletype”: “client”
}
]
i want to extract data from “rolepermission” and put it in body request
this api accept data like this
{
"role": {
"name": "Test",
"description": "Test",
"permissions": [
"manage_users",
"manage_role",
"managing_custom_page"
],
"userType":"admin"
}
}
and i convert it to this to extract data from my json file
{
"role": {
"name": "{{rolename}}",
"description": "{{roledescription}}",
"permissions": [
"{{rolepermission}}"
],
"userType": "{{roletype}}"
}
}
but he send request like this
“permissions”: [
“manage_users,view_user_logs”
],
instead it should send it like this
“permissions”: [
“manage_users”,
“view_user_logs”
],
what should i do
To save array data, you need stringify first which is mentioned here https://learning.postman.com/docs/sending-requests/variables/#understanding-variables
const res = pm.response.json();
const rolepermission = res.data[0].rolepermission;
pm.environment.set("rolepermission", JSON.stringify(rolepermission));
Use this variable in request body:
{
"role": {
"name": "{{rolename}}",
"description": "{{roledescription}}",
"permissions": {{rolepermission}},
"userType": "{{roletype}}"
}
}
I'm trying to use UpdateRecord 1.9.0 processor to modify a JSON but it does not replace the values as I want.
this is the source message
{
"type": "A",
"ids": [{
"id": "1",
"value": "abc"
}, {
"id": "2",
"value": "def"
}, {
"id": "3",
"value": "ghi"
}
]
}
and the wanted output
{
"ids": [{
"userId": "1",
}, {
"userId": "2",
}, {
"userId": "3",
}
]
}
I have configured the processor as follows
processor config
Reader:
reader
Schema registry:
schema
writer:
writer
And it works, the output is a JSON without the field 'type' and the ids have the field 'userId' instead 'id' and 'value'.
To fill the value of userId, I defined the replace strategy and the property to replace:
strategy
But the output is wrong. The userId is always filled with the id of the last element in the array:
{
"ids": [{
"userId": "3"
}, {
"userId": "3"
}, {
"userId": "3"
}
]
}
I think the value of the expression is ok because if I try to replace only one record it works fine (/ids[0]/userId, ..id)
Nifi docs has a really similar example (example 3):
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.7.1/org.apache.nifi.processors.standard.UpdateRecord/additionalDetails.html
But it does not work for me.
What am I doing wrong?
thanks
Finally I have used JoltJSONTransform processor instead UpdateRecord
JoltJSONTransform
template:
[
{
"operation": "shift",
"spec": {
"ids":{
"*":{
"id": "ids[&1].userId"
}
}
}
}
]
Easier than UpdateRecord
I've successfully created my Knowledgebase using API.
But I forgot to add some alternative questions and metadata for one of the pairs.
I've noticed PATH method in the API to update the Knowledebase, so updating kb is supported.
I've created a payload which looked like this:
{
"add": {
},
"delete": {
},
"update": {
"qnaList": [
{
"id": 1,
"answer": "Answer",
"source": "link_to_source",
"questions": [
"Question 1?",
"Question 2?"
],
"metadata": [
{
"name": "oldMetadata",
"value": "oldMetadata"
},
{
"name": "newlyAddedMetaData",
"value": "newlyAddedMetaData"
}
]
}]}
}
I get back the following response HTTP 202 Accepted:
{
"operationState": "NotStarted",
"createdTimestamp": "2018-05-21T07:46:52Z",
"lastActionTimestamp": "2018-05-21T07:46:52Z",
"userId": "user_uuid",
"operationId": "operation_uuid"
}
So, looks like it worked. But in reality, this request doesn't take any affect.
When I check operation details, it returns me the following:
{
"operationState": "Succeeded",
"createdTimestamp": "2018-05-21T07:46:52Z",
"lastActionTimestamp": "2018-05-21T07:46:54Z",
"resourceLocation": "/knowledgebases/kb_uuid",
"userId": "user_uuid",
"operationId": "operation_uuid"
}
What am I doing wrong? And how should I update my kb via API properly?
Please help
I had the same problem, I discovered that it was necessary to have all the data of the json even if they were not used.
In your case you need "name" and "urls" in the "update" section and "Delete" in "update/qnaList/questions" section:
{
"add": {},
"delete": {},
"update": {
"name": "nameofKbBase", //this
"qnaList": [
{
"id": 2370,
"answer": "DemoAnswerEdit",
"source": "CustomSource",
"questions": {
"add": [
"DemoQuestionEdit"
],
"delete": [] //this
},
"metadata": { }
}
],
"urls": [] //this
}
}
hi i want to insert data to children to Tree.but I want to put the data.for example i want to update children[0] information.Rather than creating a new one I'd like to update the existing data.
my Tree.json
{
"name": "SCATTER/BUBBLE CHART",
"id": "SCATTERBUBBLE",
"children": [
{
"name": "Series",
"id": "SERIES",
"children": [
{
"name" : "Data:X",
"id" : "DX"
},
{
"name" : "Data:Y",
"id" : "DY"
}
]
},
{
"name": "XAxis",
"id": "X"
},
{
"name": "YAxis",
"id": "Y"
}
]
}
if i click button,i want to result
{
"name": "SCATTER/BUBBLE CHART",
"id": "SCATTERBUBBLE",
"children": [
{
"name": "Series",
"id": "SERIES",
"children": [
{
"name" : "Data:X",
"id" : "DX"
},
{
"name" : "Data:Y",
"id" : "DY"
},
{
"name" : "Data:Z",
"id" : "DZ"
}
]
},
{
"name": "XAxis",
"id": "X"
},
{
"name": "YAxis",
"id": "Y"
},
{
"name": "ZAxis",
"id": "Z"
}
]
}
i don't know update children tree ask for advice
Use node.item to get the store item object which has created the node. I hope you have the node object. For instance if you want to get the root node of your tree :-
var rootNode = dijit.byId("treeID").attr("rootNode");
After you get the node's item object you may update any of its attributes and your store will be modified. Your store should also extend "dojo/store/Observable", so that your tree gets updated with the changes to store.