Pass URL Key to Webservice and Return Message
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I need to create an unsubscribe page on my website which I will link to from my emails. The link from the email will have a key parameter. I need help with the code to recognize the key from the URL, send it to the webservice, then display the message in the body of the page.

{ "status":"error", "message":"Unable to unsubscribe your email address at this time. Please contact your sales person." }

This webservice will take either a form variable named “key” or a url variable named “key” and it will return either an “error” and message that will say “Unable to unsubscribe your email address at this time. Please contact your sales person.”

Or it will return “success” and the message “some_emailaddress@domain.com has been unsubscribed.”

What language is the web service in? The best way to answer this question would be to share some code on github that we can modify to add this functionality.
sguha 6 years ago
CFM - message me privately for the actual link to the webservice
jlevey 6 years ago
awarded to kerncy

Crowdsource coding tasks.

1 Solution

Winning solution
Tipped

Hello,

here is a PHP demo that uses curl to call your webservice and then parse the JSON response in order to display the message

<?php

$key = "";
if (isset($_GET["key"])) {
    $key = $_GET["key"];
}

if (isset($_POST["key"])) {
    $key = $_POST["key"];
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/unsubscribe.cfm");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "key=" . $key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

if ($result) {
    $content = json_decode($result);
    if ($content) {
        if ($content->status == "success") {
            echo "<p>" . $content->data->Unsubscribe->Message . "</p>";
        }
        else {
            echo "<p>" . $content->message . "</p>";
        }
    }
    else {
        echo "<p>Unable to read response from webservice</p>";
    }
}
else {
    echo "<p>Unable to contact webservice : " . curl_error($ch) . "</p>";
}

curl_close($ch);

?>

Do not hesitate if you have any question,