mailjet / mailjet-apiv3-php

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

Adding new contact #244

Closed AshmitW closed 2 years ago

AshmitW commented 2 years ago

Hey, I've been trying to add contacts Using the API but I've been facing issues in it, if someone could guide me in what I am doing wrong it would be helpful. Here is what I've written

$mj = new \Mailjet\Client($apikey, $apisecret, true, ["version" => "v3"]); $body = [ "IsExcludedFromCampaigns" => "true", "email" => "ashmit@xyz.com", "firstname" => "Ashmit", "lastname" => "Shetty", "phone" => "123456", "gender" => "M", "birthday" => "22/09/1997", "dexcom" => "Dummy", "zugehoerigkeit" => "Dummy" ]; $response = $mj->post(Resources::$Contact, ["body" => $body]); $response->success() && var_dump($response->getData());

But when I return $response->getData(), I always get this: {"ErrorInfo":"","ErrorMessage":"Invalid json input: object \"\"->\"TContact\" has no property \"firstname\"","StatusCode":400}

The properties are already added, here is a screenshot showing it: image

I've also tried creating contacts in lists directly (Replaced list ID with a dummy ID, before posting here)

$mj = new \Mailjet\Client($apikey, $apisecret, true, ["version" => "v3"]); $listId = "123456"; $body = [ "Action" => "addforce", "Contacts" => [ [ "Email" => "ashmit@xyz.com", "IsExcludedFromCampaigns" => "false", "firstname" => "Ashmit", "lastname" => "Shetty", "phone" => "123456", "gender" => "M", "birthday" => "22/09/1997", "dexcom" => "Dummy", "zugehoerigkeit" => "Dummy" ] ] ]; $response = $mj->post(Resources::$ContactslistManagemanycontacts, ["id" => $listId, "body" => $body]); $response->success() && var_dump($response->getData());

But this gives me the Error, "Email is not valid" on the website.. I know I am probably doing something incorrectly but I am genuinely not sure what it is, any guidance on this is really appreciated. Thank you.

Edit: Would just like to mention if it is useful, I have tried creating a contact directly from the website without API and that works fine.