I want to retrieve only the email in a JSON response using guzzle in Laravel from an external API. Here is what I have tried
//Get all customer
$allcus = 'https://api.paystack.co/customer';
$client = new Client();
$response = $client->request('GET', $allcus, [
'headers' => [
'Authorization' => 'Bearer '.'sk_live_#########################',
],
]);
$cus_data = json_decode($response->getBody()->getContents());
//returns a json response of all customers
//dd($cus_data);
$cus_data_email = $cus_data->data->email;
dd($cus_data_email);
Using this returns error
$cus_data_email = $cus_data->data->email;
"message": "Trying to get property 'email' of non-object"
But when I tried this, it returns the customer in the first array
$cus_data_email = $cus_data->data[0]->email;
I don't want to return just one customer email. I want to retrieve all of the customers' emails.
This is the way the JSON response is
{
"status": true,
"message": "Customers retrieved",
"data": [
{
"integration": ######,
"first_name": null,
"last_name": null,
"email": "a###$gmail.com",
"phone": null,
"metadata": null,
"domain": "live",
"customer_code": "CUS_##########",
"risk_action": "default",
"id": #######,
"createdAt": "2020-05-26T00:50:12.000Z",
"updatedAt": "2020-05-26T00:50:12.000Z"
},
...