I am trying to create a basic plugin to send user details to a CRM when a user signs up on the WordPress website as a basic subscriber.
I have reached a sticking point, I have tried to interpret the API details as best as I can, but I am unsure, if I am formatting my body data properly as it just isn't working.
I can get the POST to work using Postman, however that is via json/javascript and on-site I am trying to achieve the same result using wp_remote_post
.
Any pointers or observations would be appreciated.
add_action( 'user_register', 'send_new_user', 10, 1 );
function send_new_user($user_id) {
$new_user = get_userdata($user_id);
$useremail = $new_user -> user_email;
$url = 'https://api.capsulecrm.com/api/v2/parties';
$body = array(
'firstName' => 'WhyWontYouWork',
'email' => $useremail
);
$args = array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'sslverify' => false,
'blocking' => false,
'headers' => array(
'Authorization' => 'Bearer {private token goes here!!!!}',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
),
'body' => json_encode($body),
'cookies' => array()
);
$request = wp_remote_post ($url, $args);
};
$request
variable at the end of this function?