unplugged_web Posted April 21, 2015 Share Posted April 21, 2015 I'm very new to this but am trying to add a user (and their details for an address book with dotmailer. The code I'm using, which excepts the email address okay (a new contact is created). The problem is I'm also trying to add their name, gender, address etc to the contact. To add the data I'm using: <?php/** POST EMAIL FIRST AND GET CONTACT FROM DOTMAILER */$postContactUrl = 'https://apiconnector.com/v2/contacts/';$data = array( 'Email' => 'test@email', 'EmailType' => 'Html', 'dataFields' => array('key' => 'FIRSTNAME','value'=> 'Fred','key' => 'LASTNAME','value'=> 'Smith','key' => 'FULLNAME','value'=> 'Fred Smith','key' => 'GENDER','value'=> 'Male',));//post email and response will be contact object from dotmailer$contact = execute_post($postContactUrl, $data);/** ADD CONTACT TO ADDRESS BOOK */$addContactToAddressBookUrl = 'https://apiconnector.com/v2/address-books/' . '123456' . '/contacts'; //post contact to address book and response will be address book object from dotmailer$book = execute_post($addContactToAddressBookUrl, $contact);// echo "<pre>" . print_r($contact, true) . "</pre>"; echo "<pre>" . print_r($book, true) . "</pre>";function execute_post($url, $data){ $requestBody = json_encode($data, true); $ch = curl_init(); curl_setopt($ch, CURLAUTH_BASIC, CURLAUTH_DIGEST); curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password'); // credentials curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Accept: ' . 'application/json' ,'Content-Type: application/json')); $responseBody = json_decode(curl_exec($ch)); curl_close($ch); return $responseBody;}?> The var_dump($book); shows no data at all for any of the dataFields: stdClass Object( [id] => 123456789 [email] => test@email [optInType] => Unknown [emailType] => Html [dataFields] => Array ( [3] => stdClass Object ( [key] => FIRSTNAME [value] => ) [4] => stdClass Object ( [key] => FULLNAME [value] => ) [5] => stdClass Object ( [key] => GENDER [value] => ) [7] => stdClass Object ( [key] => LASTNAME [value] => ) ) This is what I'm trying to do: http://api.dotmailer.com/v2/help/wadl#AddressBookContacts (PostAddressBookContacts in particular) but have now hit a wall and am not getting anywhere. Link to comment Share on other sites More sharing options...
unplugged_web Posted April 21, 2015 Author Share Posted April 21, 2015 I've managed to get most of it to work but didn't know if it's possible to use $_GET['email'] in an array? For example: $data = array( 'Email' => '$_GET['email']', 'EmailType' => 'Html', outputs: [email] => $_GET['email'] [optInType] => Unknown [emailType] => Html instead Link to comment Share on other sites More sharing options...
Ingolme Posted April 21, 2015 Share Posted April 21, 2015 If you want the value of $_GET['email'] then don't wrap it in quotation marks. $data = array( 'Email' => $_GET['email'], 'EmailType' => 'Html', 1 Link to comment Share on other sites More sharing options...
unplugged_web Posted April 22, 2015 Author Share Posted April 22, 2015 If you want the value of $_GET['email'] then don't wrap it in quotation marks. $data = array( 'Email' => $_GET['email'], 'EmailType' => 'Html', Brilliant thank you, I thought that all array values had to be in quotation marks! Is it the same if I want to send numbers then (i.e. I don't need the quotations)? Link to comment Share on other sites More sharing options...
unplugged_web Posted April 22, 2015 Author Share Posted April 22, 2015 Just incase anybody else is having the same problem this is the solution I used in the end: $data = array( 'Email' => $_POST['email'], 'EmailType' => 'Html', 'dataFields' => array( array( 'Key' => 'FIRSTNAME', 'Value' => $_POST['first']), array( 'Key' => 'LASTNAME', 'Value' => $_POST['last']), array( 'Key' => 'FULLNAME', 'Value' => $_POST['first']." ".$_POST['last'] ), array( 'Key' => 'GENDER', 'Value' => $_POST['gender']), )); Link to comment Share on other sites More sharing options...
Ingolme Posted April 22, 2015 Share Posted April 22, 2015 Quotation marks are used to delimit strings. If it's not a string then you don't use quotation marks. Numbers are not strings. String is just one type of data, you can read about all the different data types in the PHP tutorial: http://www.w3schools.com/php/php_datatypes.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now