Campaign Subscription Management

Messaging activities fall under the regulatory guidelines of several groups, depending on the nation in which you send the messages. For more information see Pre approved US Short Codes compliance requirements 

You use the The opt-in API to:

SMS Workflow

  1. Listen to the incoming requests and manage your recipient mailing list accordingly.
  2. Send a request.
  3. Check the response.

Unsubscribe to your campaign

Unsubscribe requests for Event Based Alerts are forwarded to the webhook endpoint you set in Dashboard  .

To handle unsubscribe requests:

  1. Listen to the incoming unsubscribe requests and manage your recipient mailing list accordingly. Once a recipient number has unsubscribed from your campaign, any outbound SMS to that number will be blocked.

  2. Send a request and see the list of phone numbers that are unsubscribed from your campaign:

    var https = require('https');
    
    var data = JSON.stringify({
     api_key: 'API_KEY',
     api_secret: 'API_SECRET'
    });
    
    var options = {
     host: 'rest.nexmo.com',
     path: 'sc/us/alert/opt-in/query/json',
     port: 443,
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
       'Content-Length': Buffer.byteLength(data)
     }
    };
    
    var req = https.request(options);
    
    req.write(data);
    req.end();
    
    var responseData = '';
    req.on('response', function(res){
     res.on('data', function(chunk){
       responseData += chunk;
     });
    
     res.on('end', function(){
       console.log(JSON.parse(responseData));
     });
    });
    

  3. Check the response:

    //Decode the json object you retrieved when you ran the request.
    
    var decodedResponse = JSON.parse(responseData);
    
    console.log('You sent ' + decodedResponse['message-count'] + ' messages.\n');
    
    decodedResponse['messages'].forEach(function(message) {
        if (message['status'] === "0") {
          console.log('Success ' + decodedResponse['message-id']);
        }
        else {
          console.log('Error ' + decodedResponse['status']  + ' ' +  decodedResponse['error-text']);
        }
    });
    

Resubscribe to your campaign

Resubscribe requests for Event Based Alerts are handled through your Website.

To handle resubscribe requests:

  1. On your website, listen to the incoming resubscribe requests.

  2. Send a request to opt-in the phone number again:

    var https = require('https');
    
    var data = JSON.stringify({
     api_key: 'API_KEY',
     api_secret: 'API_SECRET',
     msisdn: 441632960960
    });
    
    var options = {
     host: 'rest.nexmo.com',
     path: '/sc/us/alert/opt-in/manage/json',
     port: 443,
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
       'Content-Length': Buffer.byteLength(data)
     }
    };
    
    var req = https.request(options);
    
    req.write(data);
    req.end();
    
    var responseData = '';
    req.on('response', function(res){
     res.on('data', function(chunk){
       responseData += chunk;
     });
    
     res.on('end', function(){
       console.log(JSON.parse(responseData));
     });
    });
    

  3. Check the response:

    //Decode the json object you retrieved when you ran the request.
    
    var decodedResponse = JSON.parse(responseData);
    
    console.log('You sent ' + decodedResponse['message-count'] + ' messages.\n');
    
    decodedResponse['messages'].forEach(function(message) {
        if (message['status'] === "0") {
          console.log('Success ' + decodedResponse['message-id']);
        }
        else {
          console.log('Error ' + decodedResponse['status']  + ' ' +  decodedResponse['error-text']);
        }
    });