WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to integrate a 3rd party API with WordPress. I fear this is above my head. I was this code but I'm not exactly sure how to make is work in WordPress. Is it possible?

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://xxx');
curl_setopt($ch, CURLOPT_POST, 7);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
    'auth_token' => 'xxxxxx',
    'list_id' => 'xxxxx,
    'name' => 'Office',
    'campaign_id' => 'xxxxx',
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

share|improve this question

Something like this works:

$url = 'https://xxx';

$body = array(
    'auth_token' => 'xxxxxx',
    'list_id' => 'xxxxx,
    'name' => 'Office',
    'campaign_id' => 'xxxxx',

$response = wp_remote_post($url, array(
    'sslverify' => false // this is needed if your server doesn't have the latest CA certificate lists
    ) );

if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
    // error handling goes here

$results = wp_remote_retrieve_body( $response );
// $results has the actual results in it
share|improve this answer
Hi Otto- Thank you so much for the response. So I can put that in my theme functions file? – Jeces Oct 11 '12 at 16:15
Yes, you can. Be sure to wrap it as a function, though, and only call it when you need it. Otherwise it'll be executed on every page load. – EAMann Oct 11 '12 at 16:43

protected by Community May 27 at 18:20

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.