Search code examples
delphihubspotdelphi-xe8

What is the RootElement of this Content


I'm trying to use the TRESTResponseDataSetAdapter.

Every combination that I've tried for the JSON RootElement property fails

You can view the content by running this in your browser:

https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=Demo&count=1000

{
   "contacts":[
      {
         "addedAt":1405347851360,
         "vid":154835,
         "canonical-vid":154835,
         "merged-vids":[

         ],
         "portal-id":62515,
         "is-contact":true,
         "profile-token":"AO_T-mMn77ArlMSBCTdpOp0rf0qYYooZ7bHB6ehvufx9uNoV0Pyuiq1wq-A83BQmzFVFVC45T8S6tXhkq_7fcDi5Wzne7VXydwTvrKIViisZNBjWhUjJ8OiXhXW0owESlE2QCh2_rZsy",
         "profile-url":"https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMn77ArlMSBCTdpOp0rf0qYYooZ7bHB6ehvufx9uNoV0Pyuiq1wq-A83BQmzFVFVC45T8S6tXhkq_7fcDi5Wzne7VXydwTvrKIViisZNBjWhUjJ8OiXhXW0owESlE2QCh2_rZsy/",
         "properties":{
            "firstname":{
               "value":"HubSpot"
            },
            "lastmodifieddate":{
               "value":"1429569233340"
            },
            "lastname":{
               "value":"Test"
            }
         },
         "form-submissions":[
            {
               "conversion-id":"b18f9fd8-b8d3-49e5-898a-ac301fac93e9",
               "timestamp":1405347851180,
               "form-id":"b844ad5e-32bd-41e1-b0e6-ed990c5f3d1b",
               "portal-id":62515,
               "page-url":"http://demo.hubapi.com/your-stunning-headline-30",
               "page-title":"Your stunning headline!",
               "page-id":"324527",
               "title":"My New Form",
               "meta-data":[

               ]
            }
         ],
         "identity-profiles":[
            {
               "vid":154835,
               "saved-at-timestamp":1405347851237,
               "deleted-changed-timestamp":0,
               "identities":[
                  {
                     "type":"EMAIL",
                     "value":"test@hubspot.com",
                     "timestamp":1405347851180
                  },
                  {
                     "type":"LEAD_GUID",
                     "value":"c8f20860-d3d6-4b57-b092-86a07cebdcbc",
                     "timestamp":1405347851237
                  }
               ]
            }
         ],
         "merge-audits":[

         ]
      },
      {
         "addedAt":1390569372731,
         "vid":196181,
         "canonical-vid":196181,
         "merged-vids":[

         ],
         "portal-id":62515,
         "is-contact":true,
         "profile-token":"AO_T-mNWKZQBRv0UiQpPnG-WPBgVlfYwFgdTyJW3sU9frlA4esRYMOtMpo4OQMh736HGvJpuDLAuJexFXkyrIPu7eK-hxFYwGoqefbbP1cQeh6B0mRPE-iU1dhYRhRJsWyroaToFvFuo",
         "profile-url":"https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mNWKZQBRv0UiQpPnG-WPBgVlfYwFgdTyJW3sU9frlA4esRYMOtMpo4OQMh736HGvJpuDLAuJexFXkyrIPu7eK-hxFYwGoqefbbP1cQeh6B0mRPE-iU1dhYRhRJsWyroaToFvFuo/",
         "properties":{
            "firstname":{
               "value":"Charles"
            },
            "lastmodifieddate":{
               "value":"1429569231725"
            },
            "company":{
               "value":""
            },
            "lastname":{
               "value":"Gowland"
            }
         },
         "form-submissions":[

         ],
         "identity-profiles":[
            {
               "vid":196181,
               "saved-at-timestamp":1390569372649,
               "deleted-changed-timestamp":0,
               "identities":[
                  {
                     "type":"EMAIL",
                     "value":"clg@gburnette.com",
                     "timestamp":1390568711002
                  },
                  {
                     "type":"LEAD_GUID",
                     "value":"dca0d8a2-fa9c-4ca6-b5ef-c1bfb4a0bed4",
                     "timestamp":1390569372636
                  }
               ]
            }
         ],
         "merge-audits":[

         ]
      },
      {
         "addedAt":1390569372834,
         "vid":196182,
         "canonical-vid":196182,
         "merged-vids":[

         ],
         "portal-id":62515,
         "is-contact":true,
         "profile-token":"AO_T-mPTJ_EIS2780cJONDGKv5bmchukJnQ37QmmSc-lPJacEyzXo8piybhaAhQzT0HBXxq0QYXFU_4wN5ewYsclTt8WE3KAxx6neusNNYGr8aEiy-s6izAG-CCehTdomM5Pai4YOKue",
         "profile-url":"https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mPTJ_EIS2780cJONDGKv5bmchukJnQ37QmmSc-lPJacEyzXo8piybhaAhQzT0HBXxq0QYXFU_4wN5ewYsclTt8WE3KAxx6neusNNYGr8aEiy-s6izAG-CCehTdomM5Pai4YOKue/",
         "properties":{
            "firstname":{
               "value":"Curtis"
            },
            "lastmodifieddate":{
               "value":"1429569238098"
            },
            "company":{
               "value":""
            },
            "lastname":{
               "value":"Romig"
            }
         },
         "form-submissions":[

         ],
         "identity-profiles":[
            {
               "vid":196182,
               "saved-at-timestamp":1390569372699,
               "deleted-changed-timestamp":0,
               "identities":[
                  {
                     "type":"EMAIL",
                     "value":"curtis.romig@bryancave.com",
                     "timestamp":1390568725415
                  },
                  {
                     "type":"LEAD_GUID",
                     "value":"e18dc184-0238-48f1-a8a2-4476733f50d3",
                     "timestamp":1390569372641
                  }
               ]
            }
         ],
         "merge-audits":[

         ]
      },
      {
         "addedAt":1390569372757,
         "vid":196183,
         "canonical-vid":196183,
         "merged-vids":[

         ],
         "portal-id":62515,
         "is-contact":true,
         "profile-token":"AO_T-mOq49asR9pF4P9paqXhVApLjs9CXDFqCFs4BL7Y5z7TRYRoSC9i8cXxGOdXZqC-3D1doXT5G-pmAG283AFo0BYY3D-1AV2VhwIlVZ3t1KF-6G7DBQw80lRqBjPbJhtLnY7U6rd-",
         "profile-url":"https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mOq49asR9pF4P9paqXhVApLjs9CXDFqCFs4BL7Y5z7TRYRoSC9i8cXxGOdXZqC-3D1doXT5G-pmAG283AFo0BYY3D-1AV2VhwIlVZ3t1KF-6G7DBQw80lRqBjPbJhtLnY7U6rd-/",
         "properties":{
            "firstname":{
               "value":"Eugene"
            },
            "lastmodifieddate":{
               "value":"1429569256338"
            },
            "company":{
               "value":""
            },
            "lastname":{
               "value":"Klibanoff"
            }
         },
         "form-submissions":[

         ],
         "identity-profiles":[
            {
               "vid":196183,
               "saved-at-timestamp":1390569372682,
               "deleted-changed-timestamp":0,
               "identities":[
                  {
                     "type":"EMAIL",
                     "value":"eklibanoff@incomm.com",
                     "timestamp":1390568722786
                  },
                  {
                     "type":"LEAD_GUID",
                     "value":"276f1a0f-ce8f-4069-9b7a-405f9e14971a",
                     "timestamp":1390569372674
                  }
               ]
            }
         ],
         "merge-audits":[

         ]
      },
      {
         "addedAt":1390569372800,
         "vid":196184,
         "canonical-vid":196184,
         "merged-vids":[

         ],
         "portal-id":62515,
         "is-contact":true,
         "profile-token":"AO_T-mMay6vd3gbNXXOGGn7WYa4332kjWEY6hYvggd98z-MYeHHaXL8BqAHSmsGQ1VVuN9_JOUPlqQ5ZC4e0-fNjOqj-yNp23nsqldKBYY0WF-m5pgnOGEwXEV2eLNVJmFffQ0U3SXXL",
         "profile-url":"https://app.hubspot.com/contacts/62515/lists/public/contact/_AO_T-mMay6vd3gbNXXOGGn7WYa4332kjWEY6hYvggd98z-MYeHHaXL8BqAHSmsGQ1VVuN9_JOUPlqQ5ZC4e0-fNjOqj-yNp23nsqldKBYY0WF-m5pgnOGEwXEV2eLNVJmFffQ0U3SXXL/",
         "properties":{
            "firstname":{
               "value":"James C. & Brenda L."
            },
            "lastmodifieddate":{
               "value":"1429569255451"
            },
            "company":{
               "value":""
            },
            "lastname":{
               "value":"Kellling"
            }
         },
         "form-submissions":[

         ],
         "identity-profiles":[
            {
               "vid":196184,
               "saved-at-timestamp":1390569372744,
               "deleted-changed-timestamp":0,
               "identities":[
                  {
                     "type":"EMAIL",
                     "value":"jameskelling@bellsouth.net",
                     "timestamp":1390568911277
                  },
                  {
                     "type":"LEAD_GUID",
                     "value":"4b92ccc6-d777-4e3e-90d9-bc4722329c16",
                     "timestamp":1390569372738
                  }
               ]
            }
         ],
         "merge-audits":[

         ]
      }
   ],
   "has-more":true,
   "vid-offset":196184
}

I'm trying to build a ClientDataSet that includes Company, FirstName, LastName and EMAIL

Can someone please view the content and identify the correct RootElement for me ?


Solution

  • There is no plug-and-play way for this kind of data structure to map inside a TClientDataSet.

    The mapping can be done by TRESTResponseDataSetAdapter on an array of objects like this

    [
      {
        "firstname": "John",
        "lastname": "Doe",
        "email": "john@doe.com"
      },
      {
        "firstname": "Jane",
        "lastname": "Doe",
        "email": "jane@doe.com"
      }
    ]
    

    or even nested

    {
      "contacts": [
        {
          "firstname": "John",
          "lastname": "Doe",
          "email": "john@doe.com"
        },
        {
          "firstname": "Jane",
          "lastname": "Doe",
          "email": "jane@doe.com"
        }
      ]
    }
    

    when you set the RootElement property to contacts.

    But not with this kind of nested structure you are getting from your REST API.

    You have to know the structure and map that by hand