API integration with WordPress

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(
    'body'=>$body, 
    '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

Leave a Comment