mailjet / mailjet-apiv3-php

[API v3] Mailjet PHP Wrapper
http://dev.mailjet.com
MIT License
263 stars 86 forks source link

Add Contact: 404 not found #206

Closed qroac closed 3 years ago

qroac commented 4 years ago

I try to add a new contact as described. My request always ends up returning status code 404 - not found.

Is there anything I am missing?

$mj = new \Mailjet\Client(MY_KEY, MY_SECRET);
$body = [
    'Email' => $form->data('email'),
];
$response = $mj->post(\Mailjet\Resources::$Contact, ['body' => $body]);
$response->success() && var_dump($response->getData());

return $response->getStatus() . ' - '. $response->getReasonPhrase();
uavn commented 3 years ago

Is it works for you now?

If not, try to run this example from separate php file:

$mj = new \Mailjet\Client(MY_KEY, MY_SECRET);
$body = [
    'Email' => 'somebody@domain.com',
];
$response = $mj->post(\Mailjet\Resources::$Contact, ['body' => $body]);
$response->success();

print_r($response->getData());

and run it, should print something like that:

Array
(
    [0] => Array
        (
            [CreatedAt] => 2020-09-23T19:57:43Z
            [DeliveredCount] => 0
            [Email] => somebody@domain.com
            [ExclusionFromCampaignsUpdatedAt] => 
            [ID] => 207971375
            [IsExcludedFromCampaigns] => 
            [IsOptInPending] => 
            [IsSpamComplaining] => 
            [LastActivityAt] => 
            [LastUpdateAt] => 
            [Name] => 
            [UnsubscribedAt] => 
            [UnsubscribedBy] => 
        )

)

or it can be DNS problems on your host

charlylaurencier commented 3 years ago

HI, I had the same problem : I use v3.1 and you need to specify v3 when you want to manipulate contact ...

Instead of $mj = new \Mailjet\Client(MY_KEY, MY_SECRET);

Write : $mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'),true,['version' => 'v3']);