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

解決
一般投稿者

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 いいね!
承認済みベストアンサー

受理された解決策
Highlighted
一般投稿者

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.

4件の返信4
Highlighted
進行役

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?

 

Matthew Willson

HubSpot Developer Support
返信
0 いいね!
Highlighted
一般投稿者

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 いいね!
Highlighted
進行役

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? 

 

Matthew Willson

HubSpot Developer Support
返信
0 いいね!
Highlighted
一般投稿者

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.