Contact create API -> CURLOPT_POSTFIELDS populated with variables

Hi,

I am attempting to pass information from my LMS (hosted on WordPress) through to HubSpot. Currently I have it set up such that it can create a new contact by using fixed values (so this function runs after the form submits):

CURLOPT_POSTFIELDS => “{\“properties\”:{\“company\”:\“Alex\”,\“email\”:\“alex@alex.net\”,\“firstname\”:\“Alex\”,\“lastname\”:\“Alex\”,\“phone\”:\”(888) 888 888\“,\“website\”:\“alex.net\”}}”,

However, I’d like to be able to submit variables - particularly, the input values from the payment submission.

Attempted this as so:

$email1 = $_POST[‘email_address’];

CURLOPT_POSTFIELDS => “{\“properties\”:{\“company\”:\“Alex\”,\“email\”:\$email1,\“firstname\”:\“Alex\”,\“lastname\”:\“Alex\”,\“phone\”:\”(888) 888 888\“,\“website\”:\“alex.net\”}}”,

But no luck. Can anyone advise on how I might solve this?

Thanks!

Alex

Hi @ASmith3

Are you still working with this one?

Wanted to throw @tjoyce at it this to help out :grinning_face:

@ASmith3 - Have you tried

CURLOPT_POSTFIELDS => json_encode([
 'properties' => [
 'company' => 'Alex',
 'email' => $_POST['email_address'],
 'firstname' => 'Alex'
 ]
]);

Hi @dennisedson @tjoyce,

That has done it! Thank you so much, I would not like to hazard a guess at how much time that has saved me.

Thank you and have a great rest of the week!

Many thanks,

Alex