How to sign up using API?

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
I am trying to create a custom web form using the API so a new user can sign up for a newsletter. So far this much works: A user can sign up and are added to audiences. But I want to sign them up and use the functionality of the web forms in MyEmma where they will receive a confirmation email and be taking to a "Thank You" Page. Again... the following code allows them to be added to 'audience' however they are not receiving the confirmation email nor are they being redirected to the thank you page. Can someone please explain what I need to do to get this code to work properly? 

<?php// Authentication Variables
$account_id = "1788888";
$public_api_key = "e2aa25cd321c6c199999";
$private_api_key = "272e18027a49fb88888";

// Form variable(s)
// $email = $_POST['email'];
// $first_name = $_POST['first_name'];
// $last_name = $_POST['last_name'];


$email = 'designsciencelabs@gmail.com'; 
$first_name = 'Design'; 
$last_name = 'Science'; 



$groups = array(3208888);

$signup = 1835999; 
// $signup = array($signup1); 

// Member data other than email should be passed in an array called "fields"
$member_data = array(
    "email" => $email,
    "fields" => array(
        "first_name" => $first_name,
        "last_name" => $last_name
    ),
    "group_ids" => $groups,
"signup_form_id" => $signup 
);

// Set URL
$url = "https://api.e2ma.net/".$account_id."/members/add";

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_USERPWD, $public_api_key . ":" . $private_api_key);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($member_data));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($member_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

//execute post
if($http_code > 200) {
    $app_message = "Error sending subscription request";
    print_r($head);
} else {
    print_r($head);
    $app_message = "Success!";
}

echo $app_message;
?>
Photo of sparkfactor

sparkfactor

  • 1 Post
  • 0 Reply Likes

Posted 2 years ago

  • 0
  • 1
Photo of Kyle Gregory | Lipscomb University

Kyle Gregory | Lipscomb University, Champion

  • 99 Posts
  • 69 Reply Likes
Hey @sparkfactor,

I think you're looking for the "signup" API call. That one will 1) send the opt-in confirmation and 2) allow you to customize the option messaging.

POST /#account_id/members/signup

Let me know if that helps,
Kyle
Photo of Grey Stepp

Grey Stepp, Support Team Manager

  • 1700 Posts
  • 135 Reply Likes
Thanks Kyle, as always!!  :)