Join us in San Francisco on the 29/30th of October for two days of developer workshops and technical talks

Redact using an ID

In this code snippet you see how to redact a message using an ID

Example

Replace the following variables in the example code:

Key Description
NEXMO_REDACT_ID The ID of the data record that you'd like to redact
NEXMO_REDACT_TYPE The product that the ID belongs to e.g. sms

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

Create a file named transaction.js and add the following code:

Copy to Clipboard
const Nexmo = require('nexmo');

const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
});

View full source

Write the code

Add the following to transaction.js:

Copy to Clipboard
nexmo.redact.transaction(NEXMO_REDACT_ID, NEXMO_REDACT_TYPE, (err) => {
  if(err) {
    console.error(err);
  }
  // On success the API returns a 204, so there is no response
});

View full source

Run your code

Save this file to your machine and run it:

node transaction.js

Prerequisites

Install dependencies

Add the following to build.gradle:

compile 'com.nexmo:client:5.1.0'
Initialize your dependencies

Create a class named RedactATransaction and add the following code to the main method:

Copy to Clipboard
NexmoClient client = NexmoClient.builder()
        .apiKey(NEXMO_API_KEY)
        .apiSecret(NEXMO_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the RedactATransaction class:

Copy to Clipboard
RedactClient redactClient = client.getRedactClient();

redactClient.redactTransaction(NEXMO_REDACT_ID, NEXMO_REDACT_PRODUCT);

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.nexmo.quickstart.redact with the package containing RedactATransaction:

gradle run -Pmain=com.nexmo.quickstart.redact.RedactATransaction

Prerequisites

Install dependencies

composer require nexmo/client
Initialize your dependencies

Create a file named redact.php and add the following code:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);

View full source

Write the code

Add the following to redact.php:

Copy to Clipboard
// This request returns a 204 on success, and throws on error
$client->redact()->transaction(NEXMO_REDACT_ID, NEXMO_REDACT_TYPE);

View full source

Run your code

Save this file to your machine and run it:

php redact.php

Prerequisites

Install dependencies

gem install nexmo
Initialize your dependencies

Create a file named redact.rb and add the following code:

Copy to Clipboard
client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source

Write the code

Add the following to redact.rb:

Copy to Clipboard
client.redact.transaction(
  id: NEXMO_REDACT_ID,
  product: NEXMO_REDACT_TYPE
)

View full source

Run your code

Save this file to your machine and run it:

ruby redact.rb