APIs & Integrations

NDeveloper
Participant

Receiving data from engagements v3 batch endpoint in unexpected order

Hi! I started to using Create a banch of emails API endpoint from Engagements V3 and started to noticed that data not returning in the order that I sent it.

For example, here is a request body:

"inputs": [
        {
            "properties": {
                "hs_timestamp""2022-09-05T16:37:43Z",
                "hubspot_owner_id"null,
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""Subject 0",
                "hs_email_text""text 0",
                "hs_email_headers"null
            }
        },
        {
            "properties": {
                "hs_timestamp""2022-09-05T16:37:43Z",
                "hubspot_owner_id"null,
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""Subject 1",
                "hs_email_text""text 1",
                "hs_email_headers"null
            }
        }
}

It gives me response with something like that:
{
    "status""COMPLETE",
    "results": [
        {
            "id""25414471200",
            "properties": {
                "hs_body_preview""text 1",
                "hs_body_preview_html""text 1",
                "hs_body_preview_is_truncated""false",
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""Subject 1",
                "hs_email_text""text 1",
                "hs_lastmodifieddate""2022-09-07T11:03:38.976Z",
                "hs_object_id""25414471261",
                "hs_timestamp""2022-09-05T16:37:43Z"
            },
            "createdAt""2022-09-07T11:03:38.976Z",
            "updatedAt""2022-09-07T11:03:38.976Z",
            "archived"false
        },
        {
            "id""25414471260",
            "properties": {
                "hs_body_preview""text 0",
                "hs_body_preview_html""text 0",
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""Subject 0",
                "hs_email_text""text 0",
                "hs_lastmodifieddate""2022-09-07T11:03:38.976Z",
                "hs_timestamp""2022-09-05T16:37:43Z"
            },
            "createdAt""2022-09-07T11:03:38.976Z",
            "updatedAt""2022-09-07T11:03:38.976Z",
            "archived"false
        }
    ],
    "startedAt""2022-09-07T11:03:38.955Z",
    "completedAt""2022-09-07T11:03:39.103Z"
}

I increased the amount of engagements in the request and it seems like response data returned random, without any order. 
Is there any way to return the response in some order, so I could link it to the request data for association in the next request? How should I know which one created engagement is linked to one of my tasks in request? It's crucial for us before starting to use engagements v3 API.
Can anyone advice me or give more information?

Thanks for your answer!🙏

 



4 Replies 4
SNeil-Jones
Participant

Receiving data from engagements v3 batch endpoint in unexpected order

Any news on this?

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

Receiving data from engagements v3 batch endpoint in unexpected order

Hey, @NDeveloper 👋 Looking at the example responses you shared, the properties are ordered alphabetically. For example, these four are a good example of that:

hs_email_direction
hs_email_status
hs_email_subject
hs_email_text
or direction status subject text. 

Looking at the documentation, there isn't a method listed to force the response to request the ordering of your properties. I'll let the community offer any additional insights and try to tackle your additional questions.
 
Hey, @BarryGrennan @mangelet @RMones, do you have any additional thoughts for our friend @NDeveloper?
 
Thank you for taking a look! — Jaycee
linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

NDeveloper
Participant

Receiving data from engagements v3 batch endpoint in unexpected order

Hi, @Jaycee_Lewis, thank you for the reply!
Sorry, maybe I have explained myself poorly. 
I mean the actual order of items in an array that is returned. If there is an order for them - I could have the ability to link items in the response body to ones that I use in the request body in the batch endpoint. How should I know which one created engagement in a returned list is linked to one of my tasks in request? I need to save each created engagement id along with the task id on my side. Is there a way to make a returned array of created engagements be in order with array of engagements that was sent to the endpoint?
For example, for my application side, we have:

[{
    "taskId"1,
    "emailData":"emailData1",
    "contact_hsid""1"
},
{
    "taskId"2,
    "emailData":"emailData2",
    "contact_hsid""2"
},
{
    "taskId"3,
    "emailData":"emailData3",
    "contact_hsid""3"
}]
After I map my properties to properties for the "Create a batch of emails API" endpoint it becomes something like that:
{
    "inputs": [
        {
            "properties": {
                "hs_timestamp""2022-09-05T16:37:43Z",
                "hubspot_owner_id"1,
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData1",
                "hs_email_text""emailData1",
                "hs_email_headers"null
            }
        },
        {
            "properties": {
                "hs_timestamp""2022-09-05T16:37:43Z",
                "hubspot_owner_id"2,
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData2",
                "hs_email_text""emailData2",
                "hs_email_headers"null
            }
        },
        {
            "properties": {
                "hs_timestamp""2022-09-05T16:37:43Z",
                "hubspot_owner_id"2,
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData3",
                "hs_email_text""emailData3",
                "hs_email_headers"null
            }
        }
    ]
}
I receive a response with example data:
{
    "status""COMPLETE",
    "results": [
        {
            "id""a",
            "properties": {
                "hs_body_preview""emailData1",
                "hs_body_preview_html""emailData1",
                "hs_body_preview_is_truncated""false",
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData1",
                "hs_email_text""emailData1",
                "hs_lastmodifieddate""2022-09-07T11:03:38.976Z",
                "hs_object_id""1",
                "hs_timestamp""2022-09-05T16:37:43Z"
            },
            "createdAt""2022-09-07T11:03:38.976Z",
            "updatedAt""2022-09-07T11:03:38.976Z",
            "archived"false
        },
        {
            "id""c",
            "properties": {
                "hs_body_preview""emailData3",
                "hs_body_preview_html""emailData3",
                "hs_body_preview_is_truncated""false",
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData3",
                "hs_email_text""emailData3",
                "hs_lastmodifieddate""2022-09-07T11:03:38.976Z",
                "hs_object_id""25414471261",
                "hs_timestamp""2022-09-05T16:37:43Z"
            },
            "createdAt""2022-09-07T11:03:38.976Z",
            "updatedAt""2022-09-07T11:03:38.976Z",
            "archived"false
        },
        {
            "id""b",
            "properties": {
                "hs_body_preview""emailData2",
                "hs_body_preview_html""emailData2",
                "hs_email_direction""EMAIL",
                "hs_email_status""SENT",
                "hs_email_subject""emailData2",
                "hs_email_text""emailData2",
                "hs_lastmodifieddate""2022-09-07T11:03:38.976Z",
                "hs_timestamp""2022-09-05T16:37:43Z"
            },
            "createdAt""2022-09-07T11:03:38.976Z",
            "updatedAt""2022-09-07T11:03:38.976Z",
            "archived"false
        }
    ],
    "startedAt""2022-09-07T11:03:38.955Z",
    "completedAt""2022-09-07T11:03:39.103Z"
}
 
Now, I want to know that the task from my side with id '1' was created on HubSpot with id 'a'.
But how should I do it if created engagements return in a random order? Of course, I can check it by comparing the body or subject with the task from my side - but it is not a solution for us.
Can you please help me with that so I can start to use the new v3 Engagements API? If there is some sort or order option, it would be great to know!
Thank you!
 
Jaycee_Lewis
Community Manager
Community Manager

Receiving data from engagements v3 batch endpoint in unexpected order

Thanks for clarifying 😊 Hey, @LMeert @JBeatty @miljkovicmisa, do you have any insight for @NDeveloper?

 

Thank you for taking a look! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot