Trying to make GET request to Mailchimp with CURL & OAuth?

582 views Asked by At

Everything I look at online is showing how to use OAuth & Curl to make a POST request, but I want to make a get request to the Mailchimp API and I'm not getting any response it seems. I've already managed to go through the authentication and get the user's token & api URL. Now I'm just trying to pull in their lists. Here's the CURL code I've got currently:

$headers = array(
    "Content-type: application/json",
    "Authorization: OAuth ".$user['mct']
);

$curl = curl_init();
curl_setopt_array($curl,array(
    CURLOPT_URL            => "https://".$user['dc'].".api.mailchimp.com/3.0/lists",
    CURLOPT_USERAGENT      => "oauth2-draft-v10",
    CURLOPT_HTTPHEADER     => $headers,
    CURLOPT_ENCODING       => ''
));
$tresp = curl_exec($curl);
$lists = json_decode($tresp,true);

curl_close($curl);

Assuming $user['mct'] and $user['dc'] contain the proper values, any idea what I'm doing wrong here?

1

There are 1 answers

0
user3404153 On

In case anyone ends up googling and finding this, my problem was that the user information I was getting from wordpress' get_results() function was an object and not an array. Took me forever to realize because for some reason this part of my plugin is preventing me from using print_r().

Now that it's actually going to the Mailchimp API I'm able to get and debug whatever error they're sending back.