I am trying to get all the fields name against list in mailchimp fields like email address , firstname and last name etc. I am new in mailchimp i am testing with postman:
My controller code:
public function getFields()
{
$list = 'ba6de7f809';
$ch = curl_init(REQUEST_URL.$list.'/members/?fields=members.email_address','members.first_name','members.last_name');
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . 'xyz-us17');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error ( $ch );
curl_close($ch);
}
and my api route:
Route::get('getFields','ApiController@getFields');
I know there is some mistakes in my controller code i am declaring the list id in variable is it correct way to declare? and when i hit url in postman it says and i am using laravel 5.5.
Use of undefined constant REQUEST_URL - assumed 'REQUEST_URL' (this will throw an Error in a future version of PHP)
Can anyone please guide how to fetch fields name from this code: Any help would be highly appreciated!
in you controller code
$ch = curl_init(REQUEST_URL.$list.'/members/?fields=members.email_address','members.first_name','members.last_name');
The REQUEST_URL
you have used is not defined anywhere.
somewhere in you class you have to define the constant
const REQUEST_URL = 'https://usX.api.mailchimp.com/3.0'
I presume you could get this url from you mailchimp account
Additionally to get the user fields, rather than using /members/
endpoint you should use the search_members
endpoint