Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to perform a search based on email address without throwing exception? #27

Closed
ssharma0312 opened this issue Jul 15, 2018 · 6 comments

Comments

@ssharma0312
Copy link

email = "abc@test.com"
var api = new HubSpotApi(hubspotApiKey);
var contact = api.Contact.GetByEmail(email);

here the contact variable throws exception right away, is there any way we use this api to just perform search to check if this email address exist already or not without throwing exception. Since hubspot doesn't allow duplication or overriding so in order for the application to thrown exception, I want to implement alogic to check if contact already exist or not. Thanks in advance

@clarkd
Copy link
Member

clarkd commented Jul 15, 2018 via email

@chrisbaldauf
Copy link

👋 Chris from HubSpot here.

You may be interested in using the Contacts Search API Endpoint, which I've confirmed will not throw an exception if you search for an email that doesn't exist, but rather returns a 200 HTTP status code. The existing GetByEmail method could be updated to call that endpoint, or a new Search method could be added to maintain backward compatibility for existing callers of the GetByEmail method.

$ curl "https://api.hubapi.com/contacts/v1/search/query?q=abc@test.com&hapikey=$HAPIKEY"
{
  "query": "abc@test.com",
  "offset": 0,
  "has-more": false,
  "total": 0,
  "contacts": []
}

I'd be more than happy to take a look at a PR for this if someone has the time to put one together.

@clarkd
Copy link
Member

clarkd commented Jul 23, 2018

Hi Chris - thanks for reaching out!

That endpoint looks it would work well and would be a great addition to the wrapper. I'd suggest adding it as a new endpoint - overall, we're trying to mirror the HubSpot API and hence the GetByEmail() method still has its place!

@clarkd
Copy link
Member

clarkd commented Jul 31, 2018

We just released version 0.6.16 which includes a contact CreateOrUpdate method which might be helpful here too if that's what you were trying to do?

@clarkd
Copy link
Member

clarkd commented Aug 3, 2018

I'll shortly be releasing v0.6.17 which includes the Search endpoint that @chrisbaldauf mentioned - thanks to @Mark-RSK!

@clarkd clarkd closed this as completed Aug 3, 2018
@Mark-RSK
Copy link
Contributor

Mark-RSK commented Aug 3, 2018

Glad to help. This library has saved me a load of time 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants