mailerlite-api-v2-php-sdk icon indicating copy to clipboard operation
mailerlite-api-v2-php-sdk copied to clipboard

Import request not returning the expected object

Open sagerlawgeli opened this issue 3 years ago • 0 comments

/groups/:id/subscribers/import is not returning the expected response of 200, instead, it returns a data object, with more stats.

Request:

$groupsApi = (new \MailerLiteApi\MailerLite('your-api-key'))->groups();

$groupId = 123;

$subscribers = [
  [
    'email' => '[email protected]',
  	'fields' => [
    	'name' => 'John',
    	'surname' => 'Doe',
    	'company' => 'MailerLite'
  	],
  ],
  [
    'email' => '[email protected]',
  	'fields' => [
    	'name' => 'John Jr.',
    	'surname' => 'Doe',
    	'company' => 'MailerLite'
  	]
  ]
];

$addedSubscribers = $groupsApi->importSubscribers($groupId, $subscribers); 

Expected Response:

{
  "imported": [
    {
      "id": 1343991205,
      "email": "[email protected]"
    }
  ],
  "updated": [],
  "unchanged": [
    {
      "id": 1343965485,
      "email": "[email protected]"
    }
  ],
  "errors": []
}

Response I'm getting instead:

^ {#1882
  +"data": {#1876
    +"id": "xxxxxxxxxxxx"
    +"total": 42
    +"processed": 42
    +"imported": 0
    +"updated": 0
    +"errored": 42
    +"percent": 100
    +"done": true
    +"invalid": []
    +"invalidCount": 0
    +"mistyped": []
    +"mistypedCount": 0
    +"changed": []
    +"changedCount": 0
    +"unchanged": array:5 [
      0 => {#1877
        +"id": "xxxxxxxxxxxxxxxxx"
        +"email": "xxxxxxxxxxxxxxxxx"
      }
      1 => {#1878
        +"id": "xxxxxxxxxxxxxxxxx"
        +"email": "xxxxxxxxxxxxxxxxx"
      }
      2 => {#1879
        +"id": "xxxxxxxxxxxxxxxxx"
        +"email": "xxxxxxxxxxxxxxxxx"
      }
      3 => {#1880
        +"id": "xxxxxxxxxxxxxxxxx"
        +"email": "xxxxxxxxxxxxxxxxx"
      }

https://developers.mailerlite.com/reference/add-many-subscribers

sagerlawgeli avatar May 26 '22 13:05 sagerlawgeli