below is the response from soapWSDL in json.i need to print the pname,pjob .i can able to print "client":"http://xmlns.oracle.com/InternetMobile/AbsManagement/BPELProcessSubList", using alert(result.responseJSON.Envelope.Body.processResponse.client); but cant able to print sublist.pname which displays undefined error
{
"Envelope":{
"Body":{
"processResponse":{
"client":"http:\/\/xmlns.oracle.com\/InternetMobile\/AbsManagement\/BPELProcessSubList",
"subList":[
{
"personid":"30979",
"pjob":"Senior Consultant",
"pname":"Imad El Kustomany"
},
{
"personid":"30980",
"pjob":"Senior Consultant",
"pname":"Abdul Rahman Zaky"
}
],
"xmlns":"http:\/\/xmlns.oracle.com\/InternetMobile\/AbsManagement\/BPELProcessSubList"
}
},
}
Try result.responseJSON.Envelope.Body.processResponse.subList[0].pname and result.responseJSON.Envelope.Body.processResponse.subList[1].pname. subList is an array so you can loop and use index as well
Sublist is an array so you need:
alert(result.responseJSON.Envelope.Body.processResponse.client.subList[0].pname);
or if you want to display pnames of all items
result.responseJSON.Envelope.Body.processResponse.client.subList.forEach(function(el){
alert(el.pname);
});
Related
I am new to I have a JSON response from an API , which I need to parse two values in the JSON and then pass those value to the next API. The challenge I have is , I will have N number of Array JSON response similar to the sample I am Showing below ,this is one sample json but there will be n number of json concatenated of the same structure.
Now I want to retrieve the id and messages.messageId value within customers object and pass the same as input to next API call. How could I retrieve the matching id and message id and save it in a list to send to next API
"id":"64146c29",
"Customers":[
{
"id":"4a61aaf2-c6bc-41ae-9ecd-041825135bf5",
"startTime":"2022-11-29T16:00:07.623Z",
"endTime":"2022-11-29T16:00:07.630Z",
"attributes":{
"contactId":"30000236925961000-B1"
},
"provider":"Beta",
"peer":"7126e24c-affa-4fb8-a450-50a644764a32",
"messages":[
{
"messageId":"ce67fba0ef44523f0d9a9d5dd5649642"
}
],
"type":"sms",
"recipientCountry":"US",
"recipientType":"mobile"
},
{
"id":"bbed4f9c-1be7-4fe5-ba37-5e058e9f16c6",
"startTime":"2022-11-29T16:00:07.626Z",
"endTime":"2022-11-29T16:00:07.668Z",
"attributes":{
},
"provider":"Beta",
"peer":"fe49dd4a-012e-447b-b9fe-7667678756c7",
"messages":[
],
"type":"sms",
"recipientCountry":"US",
"recipientType":"tollfree"
}
],
"otherMediaUris":[
],
"selfUri":"64146c29-fe0d-4482-935e-8b86be878cb9"
} ````
To get this data (id and messageId) of each customer, you will have to loop over the customers array and return those value from each customer object.
const customersDataToSendToApi = customersDataFromApi.Customers.map(customer => {
return {customer.Id, customer.messages.messageId}
})
The customersDataToSendToApi is already an array which you can pass in the body of API POST request. I hope this helps.
Yes, you do the same thing to the array of multiple json since you say they have similar structure.
arrayOfMultipleJson.map(eachJson =>{
eachJson.Customers.map(customer => {
return {customer.Id, customer.messages.messageId}
})
})
Do you get the picture I am painting?
If you don't mind me asking, what scenario makes you get multiple JSON in one API call?
Is there a way to delete user metadata in Supabase? They offer update() option, but it seems it works as patch request, so I can't find a way to delete it.
Here's their code:
```const { user, error } = await supabase.auth.update({
data: { hello: 'world' }
});```
I tried to do this:
```const { user, error } = await supabase.auth.update({
data: {}
});```
But is doesn't do anything.
Can metadata be deleted?
Thanks
It is possible to set the metadata field to an empty JSON object (i.e. {}) but, currently, there is no way to set it to NULL. Also, you would need to know all the fields that are already stored in the metadata because you need to remove each one explicitly.
If this works for your scenario, the way to do it is to send a data object where each field that you want removed has a value of null.
For example, if you have the following JSON in your metadata: { 'field1': 2, 'field2': 'something' }, you can set the metadata to an empty JSON object like this:
supabase.auth.update({ 'data': { 'field1': null, 'field2': null } });
I want to create dynamic json from response coming from api?? How can i acheive this?? I want to have json as shown below. But i am getting invalid json. What am i doing wrong??
{
"data":[
{
"dataOverallCount":response.dataOverallCount,
"dataTotalCount":response.dataTodaysCount
}
],
"item":[
{
"itemOverallCount":response.itemOverallCount,
"itemTotalCount":response.itemTotalCount
}
]
}
here response is an object as
{dataOverallCount: 2, dataTodaysCount:0, itemOverallCount:6, itemTotalCount:3}
I am trying to get a value from the nested JSON data below. Specifically, the payments captures id value 0TA12948FV40723B is the value I need.
I try using the following codes to retrieve the value.
details.purchase_units.payments.captures.id
details.purchase_units.payments[0].captures.id
But I keep getting a console.log Error: "Order could not be captured"
JSON DATA
{
"create_time":"2019-02-19T05:06:52Z",
"update_time":"2019-02-19T05:06:52Z",
"id":"3HB96413YD922272B",
"intent":"CAPTURE",
"status":"COMPLETED",
"payer":{
"email_address":"a#yandex.com",
"payer_id":"WEJUPTK4U53E9",
"address":{
"address_line_1":"1 Main St",
"admin_area_2":"San Jose",
"admin_area_1":"CA",
"postal_code":"95131",
"country_code":"US"
},
"name":{
"given_name":"a",
"surname":"som"
},
"phone":{
"phone_number":{
"national_number":"408-214-8270"
}
}
},
"purchase_units":[{
"reference_id":"default",
"amount":{
"value":"1.01",
"currency_code":"USD"
},
"payee":{
"email_address":"gr-facilitator#yandex.com",
"merchant_id":"MSOIGVMKKWAMA"
},
"shipping":{
"name":{
"full_name":"Mr T"
},
"address":{
"address_line_1":"1234 Main St.",
"address_line_2":"Unit 1",
"admin_area_2":"Chicago",
"admin_area_1":"IL",
"postal_code":"60652","country_code":"US"
}
},
"payments":{
"captures":[{
"status":"COMPLETED",
"id":"0TA12948FV40723B",
"final_capture":true,
"create_time":"2019-02-20T05:06:52Z",
"update_time":"2019-02-20T05:06:52Z",
"amount":{
"value":"1.01","currency_code":"USD"
},
"seller_protection":{
"status":"ELIGIBLE",
"dispute_categories":[
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]}
}
]}
}]
}
Since purchase_units and captures are arrays:
details.purchase_units[0].payments.captures[0].id
captures key have objects in side an array. so you can't simply fetch like
details.purchase_units.payments[0].captures.id
you have to give the position of the captures or loop the array only you can do parsing
details.purchase_units.payments[0].captures[0].id
If you add your json as object using the chrome console you will be able to do what I did in in the image below. purchase_unit is an array so you need to access it using the index.
In case if you want to capture all the IDs in an array, you can use wild card:
details.purchase_units[*].payments.captures[*].id
This will parse complete payload for specified path and collect all the IDs in an array.
on serverside, i get a simple json file via REST with a lot of IDs, something like that:
[ {
"_id": "5825a49dasdasdasd8417c1b6d5",
}
"_id": "dfsdfsdf4960932218417c1b6d5",
}
"_id": "23434344960932218417c1b6d5",
},]
For that i have written in the main:
main.post('/..../add', Controller.addEvent);
In the Controller, i want to recieve the request and search in the mongodb for these ID's, because i need some informations about these IDs
exports.addEvent = function(req, res) {
var collection = db.get().collection('events');
My question is, if someone send me over "localhost:8080/events/add" the given simple json file, how do i have to handle this json? i need the ID's and want to search with them.
Thanks for help!
----------ADDED------------
I am bit further now. In my controller i have the following function
exports.addevent = function(req, res)
{
var ids = req.body;
console.log(ids);
}
Now i'm getting all IDs, which i have posted with "Postman" from chrome.
The output in the console is:
[ { _id: '5825a49dasdasdasd8417c1b6d5' },
{ _id: 'dfsdfsdf4960932218417c1b6d5' },
{ _id: '23434344960932218417c1b6d5' } ]
How can i have every single ID?
Ok, the request is an object and not a string. That was the error :-/
for(var i in ids) {
console.log(ids[i]._id);
}
and it works, now i can connect to the database and search for the id