APIs & Integrations

JayL
Participant

How to know when a contact batch has completed.

Hi,

 

We're using hubspot-php to upload a batch of (new) contacts. We also need to add email subscriptions to new contacts, and there is sometimes some additional details that need to get added to new contacts. 

 

The problem is that batch contact uploads are async, so they don't complete immediately, and I don't see a method to know when the batch has completed.

 

Typically these batches will have anywhere from 1 to 30 or 50 new contacts.

 

The plan is to run the "updater" process hourly (that's what we've been doing with our old email marketing provider).

 

My first thought as a work-around is to run the email subscriptions and additional data processing on the half-hour with the contact uploads on the hour. Giving the batches 30 minutes to complete. From my testing with a developer portal with batches of 100 the batches look to be processing in a minute or so. I think this should work, waiting the 30 minutes, but I'm thinking I should build in a test to see if the last contact in the batch exists to be sure...so we aren't causing errors.

 

So, is there a method to know if the batch completes? I see there's a webhook for when new contacts are created, but that's much more complicated than it should be.

 

Thanks,

Jay

0 Upvotes
7 Replies 7
quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

How to know when a contact batch has completed.

Hi @JayL 

The contact api v3 is in production stage you can use it without any issue.


zwolfson
HubSpot Employee
HubSpot Employee

How to know when a contact batch has completed.

Hey @JayL  It looks like you are using the older PHP SDK which uses an older version of the CRM APIs that isn't deterministic in how it hanldes batching. I'd recommend upgrading to the SDK @quentin_lamamy linked to which uses the new v3 APIs which will tell you in the response what failed and what succeeded. If you receive a failure response from those batch APIs, you can trust that the entire batch failed. 

 

Let me know if you have any questions.

 

Thanks,

Zack

JayL
Participant

How to know when a contact batch has completed.

Hi @zwolfson,

 

Thanks for your response! 

 

I'm using the older API because every time I click on the newer ones, like Marketing email, I see this notice "This API is currently under development. For the latest stable version check out these pages".

 

Though I just found the newer Contacts v3 API which is buried under CRM > Objects and it doesn't have that message. So, it seems like it should be the production API to use. Can you confirm it's production-ready? BTW, I had been looking for the newer Contacts API a few days ago and didn't see it because I didn't think to click on Objects. Maybe y'all can figure out a better to display that.

 

Ok, in reading through the new docs, there's a batch limit of 10, small, but workable, and it's no longer async...so that part is great. This solves the issue I was asking about.

 

Thanks for all the info! And please confirm that contacts v3 API are production ready.

 

Jay

quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

How to know when a contact batch has completed.

Hi @JayL ,
First point, are you using this sdk ? : hubspot-api-php 
I'm not sure to understand what you are trying to do, php is a sync language , if you really want to track batch update progress i think that using an async lang like nodeJs will be a better choice.

@zwolfsonan idea on this topic ?


quentin_lamamy
Key Advisor | Diamond Partner
Key Advisor | Diamond Partner

How to know when a contact batch has completed.

Thanks @dennisedson for the ping

Hi @JayL ,

 

Can you post your code here inside a code bloc (the </> icon in the format bar) ?


JayL
Participant

How to know when a contact batch has completed.

Hi @quentin_lamamy 

 

Here's the most relevant code.

 

        $response = $this->hubspot->contacts()->createOrUpdateBatch($contacts);
        $errors = $this->hubspotErrors($response);
        if ($errors['code'] == 202) return "Batch uploaded";
        else {
            $this->errorMessage .= " Upload failed, status: " . $errors['code'] . ", message was " . $errors['text'];
            return false;
        }

 

Again, I'm using the hubspot-php library.

 

Thanks,

Jay

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

How to know when a contact batch has completed.

Hey @JayL 

Thanks for the detailed question!

There is this guy @quentin_lamamy , who is pretty versed in this sdk and I am hoping he has some fresh insights for you!

0 Upvotes