Have to call API 2 times to add contact to company

companies
contacts

#1

Hi everyone, I’m working on integration HubSpot API has flow is following

  1. Create company via Create company API. And I got response 200 ok with company id
{
  "portalId": 2929785,
  "companyId": 405041263,
  "isDeleted": false,
  "properties": {...},
  "additionalDomains": []
}
  1. Create contact via Create or update contact API. And I got response 200 ok like this
{
  "vid": 2801,
  "isNew": true
}
  1. From (1) and (2), I call API to add contact to company with created companyId & created vid. And i got status 200 ok but attribute “num_associated_contacts” still equals 0.
{
  "portalId": 2929785,
  "companyId": 405041263,
  "isDeleted": false,
  "properties": {
    "website": {
      "value": "samplecompany.com",
      "timestamp": 1488973591173,
      "source": "COMPANIES",
      "sourceId": null,
      "versions": [
        {
          "name": "website",
          "value": "samplecompany.com",
          "timestamp": 1488973591173,
          "source": "COMPANIES",
          "sourceVid": []
        }
      ]
    },
    "num_associated_contacts": {
      "value": "2",...
    }
  },
  "additionalDomains": []

But the problem is, even the company is created, I can not see the contact associated with created company. But when i call the API add contact to company 2nd times, i can see now the contact associated with the company. Strange.

Btw, i did google search and found this link. This setting will enable to create company automatically and add contact to company.

In my case, I want to create company and add contact to company manually.


#2

@thang.nguyen If you want to do it manually you can just simply switch the setting off. Can you see the contact in the UI at all? Did you provide an email address to the contact when you added it?


#3

@pmanca Thanks in advance

I created company with this JSON

{
    "properties": [
        {
            "name": "name",
            "value": "A sample company name"
        },
        {
            "name": "description",
            "value": "A sample company description"
        },
        {
        	"name": "domain",
        	"value": "samplecompany.com"
        }
    ]
} 

Then, I created contact like this

{
  "properties": [
    {
      "property": "email",
      "value": "thangnguyen@samplecompany.com"
    },
    {
      "property": "firstname",
      "value": "HubSpot"
    },
    {
      "property": "lastname",
      "value": "Test"
    },
    {
      "property": "phone",
      "value": "555-122-2323"
    },
    {
      "property": "address",
      "value": "25 First Street"
    },
    {
      "property": "city",
      "value": "Cambridge"
    },
    {
      "property": "state",
      "value": "MA"
    }
  ]
}

I only dont understand, when I call API https://api.hubapi.com/companies/v2/companies/companyId/contacts/vid, API returned 200 ok but no contact associated with company. And I can not see the contact under company in Sales portal.


#4

@thang.nguyen If you go to the contact can you see a company associated to it from there? Maybe one was automatically created and assigned to it.


#5

No, i go to the contact list and can not see created company associated to it. Refresh many times but it still show no company under contact detail.


#6

@thang.nguyen Can you try and take the VID returned to you by the create contact and try and use the get contact endpoint:

Can you see the association in the response?


#7

@pmanca Strange, because i can see the company in contact detail from Sales portal, and even from API get contact via VID. Does HubSpot has problem with async data?


#8

@thang.nguyen you can see the association in the sales portal but not the marketing side? That doesn’t make any sense to me as they are both looking at the same back-end database.


#9

@pmanca i mean sometimes i see the association in Sales portal and API get contact by vid, but sometimes no. Maybe my explanation will be confused.

Dont know why, if i do test via POSTMAN with 3 APIs (create company, create/update contact, add contact to company), i get response 200 ok but i can not see the association in Sale portal (of course no in Marketing portal). Then i think API has problem with async. Because from API docs, if vid or companyId is not existed, i have to get response 404 error.


#10

@thang.nguyen can you email me your portal ID so I can take a look at it? Our APIS have no known issues with async.

pmanca@hubspot.com