I got this one working, you have to pass the json_encoded array on the body parameter of the request.
$customer_details = [
'first_name' => $first_name,
'last_name' => $last_name,
'email' => $email,
];
$customer_details['body'] = json_encode($customer_details);
$customer = $api->createUpdateCustomer($customer_details);
public function createUpdateCustomer($customer_details) {
$response = $this->apiCall( "2.0/customers", 'POST', $customer_details);
$result = json_decode($response);
return $result;
}
public function apiCall($baseUrl = null, $method = 'GET', $args = array()) {
if ( !is_null( $baseUrl ) ) {
$url = $this->baseUrl . $baseUrl;
}
else {
$url = $this->baseUrl;
}
// Populate the args for use in the wp_remote_request call
$wp_args = array_merge($args, $this->args);
$wp_args['method'] = $method;
$wp_args['timeout'] = 30;
// Make the call and store the response in $res
$res = wp_remote_request( $url, $wp_args );
// Check for success
if ( ! is_wp_error( $res ) && ( 200 == $res['response']['code'] || 201 == $res['response']['code'] ) ) {
return $res['body'];
} else {
throw new Exception( "API call didn't go well :(. Either VendHQ Connect Settings are incorrect or VendHQ server is not responding as expected." );
}
}