Thanks NogDog, your suggestion helped me find what I believe to be the cause of the issue. For some reason, there's an extra space in the variable value. See this example. when I write the entire string into a variable and echo it, this is what i get:
https://app.streamsend.com/audiences/2/people/5 /memberships.xml
Notice the space after the number 5? I believe this has to do with the fact that the ID value in my code is being pulled from an array, rather then a static value. See the code below:
# initialize a new curl session
$ch = curl_init();
$email = 'oo@example.com';
// pass my Streamsend API credentials over to the app { LoginID:Key }
curl_setopt($ch, CURLOPT_USERPWD, "**REMOVED**");
$headers = array(
'Accept: application/xml', # any data returned should be XML
'Content-Type: application/xml' # any data we send will be XML
# include any additional headers here
);
curl_setopt($ch, CURLOPT_URL, "https://app.streamsend.com/audiences/2/people.xml?email_address=$email");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Return the results as a string return value from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
# perform additional session configuration here
# execute the session and receive its response
$xmltree = curl_exec($ch);
//expolode the XML tree into an array
$array = explode(" ",$xmltree);
//just for testing purposes, to peak into the array
//print_r($array);
//Now we need to extract the USER ID from the user that was just added to the database.
list($key, $value) = $array['20'];
//assign ID to variable
$id = $array['20'];
//echo "my user ID is:" .$id;
//strip out the <id></id> tags from the source so we can pass it to the URL string
$cleanid = preg_replace("/<.+?>/","",$id);
//echo $cleanid;
//And this is where the extra space in the URL reveals itself
echo "https://app.streamsend.com/audiences/2/people/$cleanid/memberships.xml";
//var_dump($cleanid);
I'm not certain where this space is coming from. Could it be caused from using a space as the delimiter in the explode function? I think i'm really close to getting this script working. Very happy about the progress. Thanks again for your advice!
Regards,
Matt