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

Call fails when contact does not exists #93

Closed
fraincs opened this issue Apr 6, 2017 · 5 comments
Closed

Call fails when contact does not exists #93

fraincs opened this issue Apr 6, 2017 · 5 comments

Comments

@fraincs
Copy link

fraincs commented Apr 6, 2017

e.g.
$contact = $hubspot->contacts()->getByEmail("test@hubspot.com");
returns an error
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://api.hubapi.com/contacts/v1/contact/email/test@hubspot.com/profile?hapikey=APIKEYNOTSHOWNHERE resulted in a 404 Not Found response:

Digging a bit in the source of my trouble and I think that having the ability to turn off 'http_errors' on $hubspot->contacts()->getByEmail would solve my problem but I don;t know if it is doable or an option

@gmaniac
Copy link

gmaniac commented Apr 28, 2017

+1

@phena109
Copy link
Contributor

Old trick of try...catch does the job for me

try {
    $result = $hs->contacts()->getByEmail($email);
} catch (BadRequest $exc) {
    if ($exc->getCode() == 404) {

    }
}

@dsoares
Copy link

dsoares commented Oct 20, 2017

What would be the expected behavior?
From a previous commit (ebc8fb5), it was decided that Client::request would rethrow Guzzle exceptions (and not return a Response). So, i think @phena109 is right (not an old trick, it's the right way to do it, unless you change your thoughts about how hubspot-php should deal with Guzzle exceptions or 4xx / 5xx responses).

@mohammedanis
Copy link

mohammedanis commented Mar 26, 2021

This worked for me... In hubspot-php\src\Resources\Contacts.php, Line number 276 disable the http errors by replacing the line with this ['http_errors' => false],
Finally, It looks like this,

return $this->client->request(
    'get',
    $endpoint,
    ['http_errors' => false],
    build_query_string($params)
);

@ksvirkou-hubspot
Copy link
Collaborator

Hi everyone
you can pass http_errors false and Guzzle won’t throw errors

$hubspot = Factory::createWithOAuth2Token(
    'token', 
    null,
    ['http_errors' => false]
);
$response = $hubspot->contacts()->getByEmail("test@hubspot.com");

response

object(SevenShores\Hubspot\Http\Response)#18 (2) {
  ["data"]=>
  object(stdClass)#34 (5) {
    ["status"]=>
    string(5) "error"
    ["message"]=>
    string(22) "contact does not exist"
    ["correlationId"]=> ""
    ["errors"]=>
    array(1) {
      [0]=>
      object(stdClass)#35 (1) {
        ["message"]=>
        string(46) "The contact e:test@hubspot.com does not exist."
      }
    }
    ["category"]=>
    string(16) "OBJECT_NOT_FOUND"
  } ...

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

No branches or pull requests

7 participants