Sorry if this is really vague, I'm new to both cURL and interacting with API's.
Currently I have created a URL with the authentication details required that will access the API (dotmailer) and display the contacts in the address book with the given ID.
$auth_url = 'https://' . $apiemail .':' . $apipassword . '@api.dotmailer.com/v2/address-books/' . $listID .'/contacts';
Which sends me somewhere a little like this:
https://username:password@api.dotmailer.com/v2/address-books/listID/contacts
Here is the XML from that page
<ApiContact>
<Id>1058905201</Id>
<Email>email@email.com</Email>
<OptInType>Unknown</OptInType>
<EmailType>Html</EmailType>
<DataFields i:nil="true"/>
<Status>Subscribed</Status>
</ApiContact>
</ArrayOfApiContact>
Now I need to POST a variable to the API. My variable is $useremail
I was planning to use cURL to do this a I'm using PHP and avoiding SOAP instead using REST.
I'm completely new to this but I had a go with some code that doesn't work, but hey I tried!
// Authenticate
$auth_url = 'https://' . $apiemail .':' . $apipassword . '@api.dotmailer.com/v2/address-books/' . $listID .'/contacts';
// open connection
$ch = curl_init();
// set the URL
curl_setopt($ch,CURLOPT_URL, $auth_url);
curl_setopt($ch,CURLOPT_POST, $useremail);
// execute post
$result = curl_exec($ch);
// close connection
curl_close($ch);
I know this is way off but:
- This sends me to a 404 page from my API
- I know somewhere I'm missing the action that would add this to
<email>
on the XML - The documentation makes reference to the method
PostAddressBookContacts()
which I haven't mentioned, so where does this go?
Sorry if this is vague. I appreciate anyone's advice.