Related
I'm getting a response from an API, I'm interested only in one of the link that returns. I have been using for a while
["data"]["tasks"]["0"]["result"]["files"]["0"]["url"]
to get the URL but it seems the API has changed and now the "result" it changes the position 0 in every call...
{"data": {
"id": "dcd99049-63b2",
"tag": "jobbuilder",
"status": "finished",
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:28+00:00",
"ended_at": "2022-11-22T21:57:33+00:00",
"tasks": [
{
"id": "48c34a03-54f2",
"name": "task-2",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 0,
"code": null,
"message": null,
"percent": 100,
"operation": "convert",
"engine": "qpdf",
"engine_version": "10.1.0",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 633487
}
]
},
"created_at": "2022-11-22T21:57:30+00:00",
"started_at": "2022-11-22T21:57:32+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": "dd64385a-a2e9",
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": null,
"depends_on_task_ids": [
"dd64385a-a2e9",
"acfd2a2c-3c45"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/48c34a03-54f2"
}
},
{
"id": "6333e3b8-2f6f",
"name": "export-1",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 0,
"code": null,
"message": null,
"percent": 100,
"operation": "export/url",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 633487,
"url": "https://storage.cloudconvert.com/tasks/somethinglink.pdf"
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:32+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 607,
"priority": 10,
"host_name": "meggie",
"storage": "ceph-fra",
"depends_on_task_ids": [
"48c34a03-54f2"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/6333e3b8-2f6f"
}
},
{
"id": "dd64385a-a2e9",
"name": "task-2-create-watermark",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 1,
"code": null,
"message": null,
"percent": 100,
"operation": "watermark",
"engine": "imagemagick",
"engine_version": "7.1.0",
"result": {
"files": [
{
"filename": "watermark.pdf",
"size": 609229
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:30+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": "ceph-fra",
"depends_on_task_ids": [
"acfd2a2c-3c45-4e47"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/dd64385a-a2e9"
}
},
{
"id": "acfd2a2c-3c45-4e47",
"name": "task-1",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 1,
"code": null,
"message": null,
"percent": 100,
"operation": "capture-website",
"engine": "wkhtml",
"engine_version": "0.12.5",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 27330
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:28+00:00",
"ended_at": "2022-11-22T21:57:30+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": null,
"depends_on_task_ids": [],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/acfd2a2c-3c45"
}
}
],
"links": {
"self": "https://api.cloudconvert.com/v2/jobs/dcd99049-63b2-443e"
}
}};
I would like to always extract only the link:
https://storage.cloudconvert.com/tasks/somethinglink.pdf
which position can change as mentioned before... The link always start with https://storage.cloudconvert.com
I have been using this for a while to access the first object in the array
["data"]["tasks"]["0"]["result"]["files"]["0"]["url"]
but it doesn't seem to work if the link it's in a different position...
This code extracts all values as strings, then finds the one with the necessary prefix:
const data = {"data":{"id":"dcd99049-63b2","tag":"jobbuilder","status":"finished","created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:28+00:00","ended_at":"2022-11-22T21:57:33+00:00","tasks":[{"id":"48c34a03-54f2","name":"task-2","job_id":"dcd99049-63b2","status":"finished","credits":0,"code":null,"message":null,"percent":100,"operation":"convert","engine":"qpdf","engine_version":"10.1.0","result":{"files":[{"filename":"something.pdf","size":633487}]},"created_at":"2022-11-22T21:57:30+00:00","started_at":"2022-11-22T21:57:32+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":"dd64385a-a2e9","user_id":6070,"priority":10,"host_name":"meggie","storage":null,"depends_on_task_ids":["dd64385a-a2e9","acfd2a2c-3c45"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/48c34a03-54f2"}},{"id":"6333e3b8-2f6f","name":"export-1","job_id":"dcd99049-63b2","status":"finished","credits":0,"code":null,"message":null,"percent":100,"operation":"export/url","result":{"files":[{"filename":"something.pdf","size":633487,"url":"https://storage.cloudconvert.com/tasks/somethinglink.pdf"}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:32+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":607,"priority":10,"host_name":"meggie","storage":"ceph-fra","depends_on_task_ids":["48c34a03-54f2"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/6333e3b8-2f6f"}},{"id":"dd64385a-a2e9","name":"task-2-create-watermark","job_id":"dcd99049-63b2","status":"finished","credits":1,"code":null,"message":null,"percent":100,"operation":"watermark","engine":"imagemagick","engine_version":"7.1.0","result":{"files":[{"filename":"watermark.pdf","size":609229}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:30+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":6070,"priority":10,"host_name":"meggie","storage":"ceph-fra","depends_on_task_ids":["acfd2a2c-3c45-4e47"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/dd64385a-a2e9"}},{"id":"acfd2a2c-3c45-4e47","name":"task-1","job_id":"dcd99049-63b2","status":"finished","credits":1,"code":null,"message":null,"percent":100,"operation":"capture-website","engine":"wkhtml","engine_version":"0.12.5","result":{"files":[{"filename":"something.pdf","size":27330}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:28+00:00","ended_at":"2022-11-22T21:57:30+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":6070,"priority":10,"host_name":"meggie","storage":null,"depends_on_task_ids":[],"links":{"self":"https://api.cloudconvert.com/v2/tasks/acfd2a2c-3c45"}}],"links":{"self":"https://api.cloudconvert.com/v2/jobs/dcd99049-63b2-443e"}}}
const f=i=>i instanceof Object?Object.values(i).flatMap(v=>f(v)):[i+'']
console.log(f(data).find(i=>
i.startsWith('https://storage.cloudconvert.com/tasks/')))
I'm currently working on a personal project, which is an E-Commerce Web App. To do this, I used the Commerce.js library and is currently hitting a roadblock. Although technically I can do this by using nested for loops, I would like to look for a more efficient method that uses cleaner code and is faster and more efficient with resources.
The Commerce.js documentation does not return the products in a certain category, therefore I have to use two functions to get them seperately.
const commerce = new Commerce(process.env.REACT_APP_API_KEY)
var shopItems;
var categoriesList;
useEffect(()=> {
commerce.categories.list().then((categories) => {
categoriesList = categories;
console.log(categoriesList.data)
});
commerce.products.list().then((product) => {
shopItems = product;
console.log(shopItems.data)
});
})
DATA
Categories:
{
"id": "cat_O3bR5XyEklnzdj",
"parent_id": null,
"slug": "new-releases",
"name": "New Releases",
"description": null,
"products": 1,
"created": 1639555008,
"updated": 1639555008,
"meta": null,
"assets": [
{
"id": "ast_Op1YoVxzaglXLv",
"url": "https://cdn.chec.io/merchants/37076/assets/aHVfA98RM9vVKjMa|Screenshot (6).png",
"description": null,
"is_image": true,
"filename": "Screenshot (6).png",
"file_size": 933236,
"file_extension": "png",
"image_dimensions": {
"width": 1920,
"height": 1080
},
"meta": [],
"created_at": 1639555026,
"updated_at": 1639555031
}
],
"children": []
}
Products:
[
{
"id": "prod_RyWOwmdx1GlnEa",
"created": 1639554903,
"updated": 1639554964,
"active": true,
"permalink": "tE45fb",
"name": "Air Jordan 11 Cool Grey",
"description": "<p></p>",
"price": {
"raw": 300000,
"formatted": "300,000.00",
"formatted_with_symbol": "Rp300,000.00",
"formatted_with_code": "300,000.00 IDR"
},
"inventory": {
"managed": false,
"available": 0
},
"sku": null,
"sort_order": 0,
"seo": {
"title": null,
"description": null
},
"thank_you_url": null,
"meta": null,
"conditionals": {
"is_active": true,
"is_tax_exempt": false,
"is_pay_what_you_want": false,
"is_inventory_managed": false,
"is_sold_out": false,
"has_digital_delivery": false,
"has_physical_delivery": false,
"has_images": true,
"collects_fullname": false,
"collects_shipping_address": false,
"collects_billing_address": false,
"collects_extra_fields": false
},
"is": {
"active": true,
"tax_exempt": false,
"pay_what_you_want": false,
"inventory_managed": false,
"sold_out": false
},
"has": {
"digital_delivery": false,
"physical_delivery": false,
"images": true
},
"collects": {
"fullname": false,
"shipping_address": false,
"billing_address": false,
"extra_fields": false
},
"checkout_url": {
"checkout": "https://checkout.chec.io/tE45fb?checkout=true",
"display": "https://checkout.chec.io/tE45fb"
},
"extra_fields": [],
"variant_groups": [],
"categories": [],
"assets": [
{
"id": "ast_8XO3wpM74OoYAz",
"url": "https://cdn.chec.io/merchants/37076/assets/1WUVJv226CmE5Xp2|air-jordan-11-cool-grey-ct8012-005-release-date (1).jpg",
"description": null,
"is_image": true,
"filename": "air-jordan-11-cool-grey-ct8012-005-release-date (1).jpg",
"file_size": 24857,
"file_extension": "jpg",
"image_dimensions": {
"width": 960,
"height": 1080
},
"meta": [],
"created_at": 1639554944,
"updated_at": 1639554948
},
{
"id": "ast_bO6J5aBxDElEjp",
"url": "https://cdn.chec.io/merchants/37076/assets/xRQc9seG948wu332|download (1).jfif",
"description": null,
"is_image": true,
"filename": "download (1).jfif",
"file_size": 7152,
"file_extension": "jpg",
"image_dimensions": {
"width": 294,
"height": 171
},
"meta": [],
"created_at": 1639554948,
"updated_at": 1639554949
},
{
"id": "ast_A12JwrMQExlPjn",
"url": "https://cdn.chec.io/merchants/37076/assets/5RmVeAD6AX6l1O7D|download.jfif",
"description": null,
"is_image": true,
"filename": "download.jfif",
"file_size": 5551,
"file_extension": "jpg",
"image_dimensions": {
"width": 266,
"height": 190
},
"meta": [],
"created_at": 1639554959,
"updated_at": 1639554961
}
],
"image": {
"id": "ast_8XO3wpM74OoYAz",
"url": "https://cdn.chec.io/merchants/37076/assets/1WUVJv226CmE5Xp2|air-jordan-11-cool-grey-ct8012-005-release-date (1).jpg",
"description": null,
"is_image": true,
"filename": "air-jordan-11-cool-grey-ct8012-005-release-date (1).jpg",
"file_size": 24857,
"file_extension": "jpg",
"image_dimensions": {
"width": 960,
"height": 1080
},
"meta": [],
"created_at": 1639554944,
"updated_at": 1639554948
},
"related_products": [],
"attributes": []
},
{
"id": "prod_BkyN5YVzyxl0b6",
"created": 1639564691,
"updated": 1639564756,
"active": true,
"permalink": "BPMQ0E",
"name": "Air Jordan 5 Green Bean",
"description": "",
"price": {
"raw": 400000,
"formatted": "400,000.00",
"formatted_with_symbol": "Rp400,000.00",
"formatted_with_code": "400,000.00 IDR"
},
"inventory": {
"managed": false,
"available": 0
},
"sku": null,
"sort_order": 0,
"seo": {
"title": null,
"description": null
},
"thank_you_url": null,
"meta": null,
"conditionals": {
"is_active": true,
"is_tax_exempt": false,
"is_pay_what_you_want": false,
"is_inventory_managed": false,
"is_sold_out": false,
"has_digital_delivery": false,
"has_physical_delivery": false,
"has_images": true,
"collects_fullname": false,
"collects_shipping_address": false,
"collects_billing_address": false,
"collects_extra_fields": false
},
"is": {
"active": true,
"tax_exempt": false,
"pay_what_you_want": false,
"inventory_managed": false,
"sold_out": false
},
"has": {
"digital_delivery": false,
"physical_delivery": false,
"images": true
},
"collects": {
"fullname": false,
"shipping_address": false,
"billing_address": false,
"extra_fields": false
},
"checkout_url": {
"checkout": "https://checkout.chec.io/BPMQ0E?checkout=true",
"display": "https://checkout.chec.io/BPMQ0E"
},
"extra_fields": [],
"variant_groups": [],
"categories": [
{
"id": "cat_O3bR5XyEklnzdj",
"slug": "new-releases",
"name": "New Releases"
}
],
"assets": [
{
"id": "ast_8XO3wpM7yOoYAz",
"url": "https://cdn.chec.io/merchants/37076/assets/L4NaqCsUMMxS6Ie8|2022-Air-Jordan-5-Green-Bean-1068x707.jpg",
"description": null,
"is_image": true,
"filename": "2022-Air-Jordan-5-Green-Bean-1068x707.jpg",
"file_size": 60899,
"file_extension": "jpg",
"image_dimensions": {
"width": 1068,
"height": 707
},
"meta": [],
"created_at": 1639564675,
"updated_at": 1639564678
}
],
"image": {
"id": "ast_8XO3wpM7yOoYAz",
"url": "https://cdn.chec.io/merchants/37076/assets/L4NaqCsUMMxS6Ie8|2022-Air-Jordan-5-Green-Bean-1068x707.jpg",
"description": null,
"is_image": true,
"filename": "2022-Air-Jordan-5-Green-Bean-1068x707.jpg",
"file_size": 60899,
"file_extension": "jpg",
"image_dimensions": {
"width": 1068,
"height": 707
},
"meta": [],
"created_at": 1639564675,
"updated_at": 1639564678
},
"related_products": [],
"attributes": []
}
]
is there a way to efficiently and cleanly find products based on their categories? Thank you in advance.
Yes. There is a way by using the category 'slug'.
import Commerce from '#chec/commerce.js';
const commerce = new Commerce('{your_public_key}');
// Fetch products specifying a category slug
commerce.products.list({
category_slug: ['shoes'],
}).then(response => response.data);
// Fetch products specifying multiple category slugs
commerce.products.list({
category_slug: ['shoes', 'black'],
}).then(response => response.data);
For more details:
https://commercejs.com/docs/sdk/products#retrieve-product
[
{
"User": 0,
"UserGroupId": 0,
"ContentType": "PhotoAlbums",
"EventName": "Album Name",
"ContentDescription": "Description",
"ContentForIsAll": 3,
"CollectionId": 0,
"IsCommentable": true,
"IsShareable": true,
"IsStory": false,
"IsHidden": false,
"IsDeleted": false,
"IsBlock": false,
"CssClass": null,
"Active": false,
"PageId": 0,
"EventStart": null,
"EventEnd": null,
"LastIpAddress": null,
"CreatedOn": "2018-07-25T14:46:34.93",
"LikeCount": 1,
"ShareCount": 0,
"CommentCount": 0,
"PageIndex": 0,
"PageSize": 0,
"UserId": {
"UserType": 0,
"UserName": "admin#admin.com",
"Password": null,
"FirstName": "Administrator",
"LastName": "-",
"Address1": null,
"Address2": null,
"City": null,
"StateProvince": null,
"ZipPostalCode": null,
"EmailAddress": null,
"LocationName": null,
"CompanyName": null,
"Sex": null,
"DateofBirth": null,
"ProfileImage": "default_avatar.jpg",
"DisplayImage": "default_avatar.jpg",
"IsBlock": false,
"RemainingEarningToken": 0,
"IsOnline": false,
"MobileNo": null,
"IsMobileConfirm": false,
"IsEmailConfirm": false,
"IsForgotPass": false,
"Active": false,
"SystemName": null,
"ConnectionId": null,
"ParentId": null,
"SaltKey": null,
"ShareLink": null,
"CssClass": null,
"IsLikeAccess": false,
"IsCommentAccess": false,
"IsShareAccess": false,
"LastIpAddress": null,
"CreatedOnUtc": "0001-01-01T00:00:00",
"UpDatedOnUtc": "0001-01-01T00:00:00",
"LastLoginDateUtc": null,
"LastActivityDateUtc": "0001-01-01T00:00:00",
"AccessToken": null,
"PageIndex": 0,
"PageSize": 0,
"UserTypeId": null,
"Id": 1
},
"PostDetailsEntityList": [ Want to display this array Path
{
"PostId": 8,
"Name": "2018-07-25_02-46-34-PMchicken_rost.jpg",
"Path": "2018-07-25_02-46-34-PMchicken_rost.jpg",
"DetailContentType": "ImageText",
"CreatedOn": "2018-07-25T14:46:34.987",
"Id": 8
},
{
"PostId": 8,
"Name": "2018-07-25_02-46-34-PMcrispy.jpg",
"Path": "2018-07-25_02-46-34-PMcrispy.jpg",
"DetailContentType": "ImageText",
"CreatedOn": "2018-07-25T14:46:34.987",
"Id": 9
},
{
"PostId": 8,
"Name": "2018-07-25_02-46-34-PMdownload1.jpg",
"Path": "2018-07-25_02-46-34-PMdownload1.jpg",
"DetailContentType": "ImageText",
"CreatedOn": "2018-07-25T14:46:34.987",
"Id": 10
},
{
"PostId": 8,
"Name": "2018-07-25_02-46-34-PMdownload2.jpg",
"Path": "2018-07-25_02-46-34-PMdownload2.jpg",
"DetailContentType": "ImageText",
"CreatedOn": "2018-07-25T14:46:34.987",
"Id": 11
}
],
"PostCommentEntityList": [
],
"Id": 8
},
{
"User": 0,
"UserGroupId": 0,
"ContentType": "Event",
"EventName": "Test Event",
"ContentDescription": "Description\r\n",
"ContentForIsAll": 3,
"CollectionId": 0,
"IsCommentable": true,
"IsShareable": true,
"IsStory": false,
"IsHidden": false,
"IsDeleted": false,
"IsBlock": false,
"CssClass": null,
"Active": false,
"PageId": 0,
"EventStart": "2018-07-09T16:01:00",
"EventEnd": "2018-07-17T17:01:00",
"LastIpAddress": null,
"CreatedOn": "2018-07-25T14:30:37.347",
"LikeCount": 0,
"ShareCount": 0,
"CommentCount": 0,
"PageIndex": 0,
"PageSize": 0,
"UserId": {
"UserType": 0,
"UserName": "admin#admin.com",
"Password": null,
"FirstName": "Administrator",
"LastName": "-",
"Address1": null,
"Address2": null,
"City": null,
"StateProvince": null,
"ZipPostalCode": null,
"EmailAddress": null,
"LocationName": null,
"CompanyName": null,
"Sex": null,
"DateofBirth": null,
"ProfileImage": "default_avatar.jpg",
"DisplayImage": "default_avatar.jpg",
"IsBlock": false,
"RemainingEarningToken": 0,
"IsOnline": false,
"MobileNo": null,
"IsMobileConfirm": false,
"IsEmailConfirm": false,
"IsForgotPass": false,
"Active": false,
"SystemName": null,
"ConnectionId": null,
"ParentId": null,
"SaltKey": null,
"ShareLink": null,
"CssClass": null,
"IsLikeAccess": false,
"IsCommentAccess": false,
"IsShareAccess": false,
"LastIpAddress": null,
"CreatedOnUtc": "0001-01-01T00:00:00",
"UpDatedOnUtc": "0001-01-01T00:00:00",
"LastLoginDateUtc": null,
"LastActivityDateUtc": "0001-01-01T00:00:00",
"AccessToken": null,
"PageIndex": 0,
"PageSize": 0,
"UserTypeId": null,
"Id": 1
},
"PostDetailsEntityList": [
{
"PostId": 7,
"Name": "2018-07-25_02-30-15-PMabba_ios_icon01_370x370.jpg",
"Path": "2018-07-25_02-30-15-PMabba_ios_icon01_370x370.jpg",
"DetailContentType": "ImageText",
"CreatedOn": "2018-07-25T14:31:24.833",
"Id": 7
}
],
"PostCommentEntityList": [
],
"Id": 7
}
]
This question already has an answer here:
Receive and log webhook post
(1 answer)
Closed 8 years ago.
I have created the coldfusion file to catch the STRIPE webhook response.
<cfsavecontent variable="headerdump">
<cfdump var="#toString(getHttpRequestData().content, 'utf-8')#" expand="yes" format="text">
</cfsavecontent>
When i print the headerdump, got the below response. I want to extract the node values of the output text.
<pre>{
"id": "evt_1041EO45YXiN2y2zPhZbNrgh",
"created": 1399872268,
"livemode": false,
"type": "invoice.payment_succeeded",
"data": {
"object": {
"date": 1399872268,
"id": "in_1041EO45YXiN2y2zQF1xhLyl",
"period_start": 1399872268,
"period_end": 1399872268,
"lines": {
"object": "list",
"total_count": 1,
"has_more": false,
"url": "/v1/invoices/in_1041EO45YXiN2y2zQF1xhLyl/lines",
"data": [
{
"id": "sub_41EOmzNFelCyAL",
"object": "line_item",
"type": "subscription",
"livemode": false,
"amount": 0,
"currency": "usd",
"proration": false,
"period": {
"start": 1399872268,
"end": 1399958668
},
"quantity": 1,
"plan": {
"interval": "month",
"name": "test one day",
"created": 1399536505,
"amount": 500,
"currency": "usd",
"id": "test_001",
"object": "plan",
"livemode": false,
"interval_count": 1,
"trial_period_days": 1,
"metadata": {
},
"statement_description": "half day trial"
},
"description": null,
"metadata": null
}
]
},
"subtotal": 0,
"total": 0,
"customer": "cus_41EOvhzjYGx7ci",
"object": "invoice",
"attempted": true,
"closed": true,
"paid": true,
"livemode": false,
"attempt_count": 0,
"amount_due": 0,
"currency": "usd",
"starting_balance": 0,
"ending_balance": null,
"next_payment_attempt": null,
"charge": null,
"discount": null,
"application_fee": null,
"subscription": "sub_41EOmzNFelCyAL",
"metadata": {
},
"description": null
}
},
"object": "event",
"pending_webhooks": 1,
"request": "iar_41EO1vDF1gpnPn"
}</pre>
Please suggest how to read this either in coldfusion or javascript.
Thanks
I do something like this:
<cfscript>
variables.requestdata = getHTTPRequestData();
variables.sStripeData = toString(variables.requestdata.content);
variables.stStripeData = deserializeJSON(variables.sStripeData);
</cfscript>
$("#loginsubmit").live("click", function() {
var request = new Request();
request.service = "http://88.80.223.163:8080/lumiin-service/lumiin/control/eventmap/1" ;
RequestHandler(request,displayData);
});
function displayData(data) {
//alert(data.contents.ownerId);
var cont = data.contents;
$("#mono").html(''+cont.id);
}
I am using the above code snippet to get the id, which works fine...How do I get the firstName?
Object:
{
"id": 1,
"eventId": {
"URL": "web",
"location": "web",
"url": "web",
"id": 54,
"type": {
"name": "Meeting",
"id": 1,
"isDeleted": "N",
"description": "Meeting"
},
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"eventName": "Tanvi",
"place": "web",
"startDate": 1335830400000,
"endDate": 1337558400000,
"prospectId": null,
"person": "web",
"isDeleted": "N",
"countryId": {
"name": "CH",
"id": 1,
"isDeleted": "N",
"description": "Switzerland"
},
"followUp": null,
"budget": 0,
"description": "web"
},
"ownerId": {
"id": 67,
"firstName": "web123",
"localOrg": null,
"industryTypeId": null,
"memeber": false,
"profileType": "Manager",
"emailId": "web123",
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"userCode": "web123",
"authenticatedAccess": -1,
"uuid": null,
"lastName": "web123",
"isDeleted": "N",
"passWord": "web123",
"fullName": "web123,web123",
"status": 0
},
"prospectId": {
"id": 303,
"firstName": "web123",
"emailId": "web123#gg.com",
"ownerId": {
"id": 67,
"firstName": "web123",
"localOrg": null,
"industryTypeId": null,
"memeber": false,
"profileType": "Manager",
"emailId": "web123",
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"userCode": "web123",
"authenticatedAccess": -1,
"uuid": null,
"lastName": "web123",
"isDeleted": "N",
"passWord": "web123",
"fullName": "web123,web123",
"status": 0
},
"abteilung": {
"id": 165,
"code": "web123",
"isDeleted": null,
"domainId": 0,
"parentId": 164,
"description": null
},
"startDate": 1335744000000,
"endDate": 1337904000000,
"statusId": {
"name": "New",
"id": 1,
"isDeleted": "N",
"description": "New"
},
"company": "company",
"lastName": "web123",
"isDeleted": "N",
"yearofBirth": null,
"annualRevenue": 0,
"nationalityId": {
"name": "CH",
"id": 1,
"isDeleted": "N",
"description": "Switzerland"
},
"titleId": {
"name": "Mr",
"id": 1,
"isDeleted": "N",
"description": "Mr"
},
"maritalstatusId": null,
"residencyId": null,
"languageId": null,
"priorityId": {
"name": "Low",
"id": 1,
"isDeleted": "N",
"description": "Low"
},
"genderId": {
"name": "Male",
"id": 1,
"isDeleted": "N",
"description": "Male"
}
},
"isDeleted": "N"
}
The firstName is a property of the prospectId object you can read it in this way:
var firstName = data.prospectId.firstName;
var lastName = data.prospectId.lastName;
Fiddle