APIs & Integrations

fellipe
Member

Some times doesn't find a company that have domain and was auto created

SOLVE

When a user submit form from my site, first i use /contact/createOrUpdate/email/ to create contact.

If the user email domain is gmail,hotmail,etc, will create a company. If no, it will search for the company with the email domain, because we have auto create company from domain set on.

With that, i create a deal and associate with vid and companyId. With the deal created, i send to create a note for the deal.

So, the problem is that sometimes api that search company with a domain, doesn't find sometimes. I'm already using async and await.

0 Upvotes
1 Accepted solution
fellipe
Solution
Member

Some times doesn't find a company that have domain and was auto created

SOLVE

Ok, i put Task.Delay(1000) on that method, and it's working with some test's i did.  Already published on server and going see, if it's going create deal with contact and company related when a client submit the form.

View solution in original post

4 Replies 4
Willson
HubSpot Employee
HubSpot Employee

Some times doesn't find a company that have domain and was auto created

SOLVE

Hi @fellipe 

 

In order to assist here, would you be able to provide some details of the calls you're making, which endpoints you're using when you're encountering this issue with the incorrect values being returned or, in this case, a record is missing from your query?

 

Product Manager @ HubSpot
0 Upvotes
fellipe
Member

Some times doesn't find a company that have domain and was auto created

SOLVE

Hi @Willson 

 

I'm using the  /companies/v2/domains/:domain/companies endpoint.

 

The issue, is that sometimes doesn't find the company. Below is the code i'm using to search.

Could it be when i call this endpoint, the company is not created?

 

 

protected async Task<string> BuscarEmpresaDominio(ContatoViewModel cad, string apiKey)
        {
            var idCompany = string.Empty;

            MailAddress address = new MailAddress(cad.Email);
            string dominio = address.Host;

            var httpWebRequestHubSpotDomain = (HttpWebRequest)WebRequest.Create("https://api.hubapi.com/companies/v2/domains/" + dominio + "/companies?hapikey=" + apiKey);
            httpWebRequestHubSpotDomain.ContentType = "application/json";
            httpWebRequestHubSpotDomain.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequestHubSpotDomain.GetRequestStream()))
            {
                string jsonDomain = new JavaScriptSerializer().Serialize(new
                {
                    limit = "1",
                    requestOptions = new
                    {
                        properties = new object[]
                        {
                                "domain"
                        }
                    },
                    offset = new
                    {
                        isPrimary = "true",
                        companyId = "0"
                    }
                });

                streamWriter.Write(jsonDomain);
            }

            var httpResponseHubSpotDomain = (HttpWebResponse)httpWebRequestHubSpotDomain.GetResponse();

            var wDominio = "";
            if (httpResponseHubSpotDomain.StatusCode == HttpStatusCode.OK)
            {
                string wDomain;

                using (var streamReader = new StreamReader(httpResponseHubSpotDomain.GetResponseStream()))
                {
                    wDomain = streamReader.ReadToEnd();
                }

                dynamic domainDes = JsonConvert.DeserializeObject(wDomain);

                for (int i = 0; i < domainDes.results.Count; i++)
                {
                    wDominio = Convert.ToString(domainDes.results[i].companyId);
                }

                idCompany = wDominio;
            }

            return idCompany;
        }

 

 

0 Upvotes
Willson
HubSpot Employee
HubSpot Employee

Some times doesn't find a company that have domain and was auto created

SOLVE

Hi @fellipe 

 

"Could it be when i call this endpoint, the company is not created?"

This could very well be the issue, have you tried this with a delay to ensure there is enough of a delay to allow the record to be created? 

 

Product Manager @ HubSpot
0 Upvotes
fellipe
Solution
Member

Some times doesn't find a company that have domain and was auto created

SOLVE

Ok, i put Task.Delay(1000) on that method, and it's working with some test's i did.  Already published on server and going see, if it's going create deal with contact and company related when a client submit the form.