DELETE to /api/account/ACCOUNT_CODE/subscriptions.xml
For an email subscriber
<subscriber>
<email>EMAIL@ADDRESS.COM</email>
<send-notifications type='boolean'>false</send-notifications>
<topics type='array'>
<topic>
<code>####</code>
</topic>
<topic>
<code>####</code>
</topic>
</topics>
</subscriber>
For a wireless subscriber
<subscriber>
<phone>###-###-####</phone>
<country-code>#</country-code>
<send-notifications type='boolean'>false</send-notifications>
<topics type='array'>
<topic>
<code>####</code>
</topic>
<topic>
<code>####</code>
</topic>
</topics>
</subscriber>
<?xml version="1.0" encoding="UTF-8"?> <subscriber> <to-param>dGVzdDAxQHRlc3QuZ292ZGVsaXZlcnkuY29t</to-param> <link rel="self" href="/api/account/ACCOUNT_CODE/subscribers/dGVzdDAxQHRlc3QuZ292ZGVsaXZlcnkuY29t"/> <subscriber-uri>/api/account/ACCOUNT_CODE/subscribers/dGVzdDAxQHRlc3QuZ292ZGVsaXZlcnkuY29t</subscriber-uri> </subscriber>
<?php
/*
Replace or create a subscriber's subscriptions
*/
require_once 'HTTP/Request2.php';
if($argc < 4)
{
print "Add subscriptions to a subscriber\n";
print "usage: $argv[0] account_code email_address \"topic1,topic2,topic3,...\" username password\n\n";
exit;
}
$account_code = $argv[1];
$destination = $argv[2];
$topics = $argv[3];
$username = $argv[4];
$password = $argv[5];
// lower case the email first, then base64 encode it
$encoded_email = base64_encode(strtolower($email_address));
// split the list of topics
$topic_list = split(",", $topics);
$url = "https://stage-api.govdelivery.com/api/account/$account_code/subscriptions";
try
{
$request =
new HTTP_Request2
(
$url,
HTTP_Request2::METHOD_DELETE,
array ('ssl_verify_peer' => false,
'ssl_verify_host' => false)
);
$request -> setAuth($username, $password, HTTP_Request2::AUTH_BASIC);
$request_body =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
" <subscriber>";
if(substr_count($destination, "@") > 0)
{
$request_body .= " <email>$destination</email>";
}
else
{
$request_body .= " <phone>$destination</phone>";
$request_body .= " <country-code>1</country-code>";
}
$request_body .= " <send-notifications type='boolean'>false</send-notifications>";
$request_body .= " <topics type='array'>";
foreach($topic_list as &$topic)
{
$request_body .= " <topic>";
$request_body .= " <code>$topic</code>";
$request_body .= " </topic>";
}
$request_body .= " </topics>";
$request_body .= " </subscriber>";
$request
-> setHeader('Content-type: text/xml; charset=utf-8')
-> setBody($request_body);
print "Connecting with ";
print_r($request);
print "\n";
$response = $request -> send();
echo "Response status: " . $response -> getStatus() . "\n";
echo "Human-readable reason phrase: " . $response -> getReasonPhrase() . "\n";
echo "Response HTTP version: " . $response -> getVersion() . "\n";
echo "Response object:\n";
print_r($response) . "\n";
if($response->getHeader('content-encoding') == 'gzip')
{
echo "Gzipped!\n";
$response_body = $response -> decodeGzip($response->getBody());
}
else
{
$response_body = $response -> getBody();
}
echo "Response payload\n";
echo $response_body;
if($response -> getStatus() != 200)
{
// log an error
print "Got a non-successful return code, please inspect the response body\n";
}
}
catch(Exception $e)
{
print "\n";
echo "ERROR " . $e->getMessage() . "\n";
print_r($e) . "\n";
print "Response: \n";
print_r($response) . "\n";
}
?>
Reference subscriber error codes
Was this page helpful? Can't find what you need? Let us know