Node.js Stripe: Create a PII Token

Back to Index

Creates a single use token that wraps the details of personally identifiable information (PII). This token can be used in place of a personal_id_number in the Account Update API method. These tokens can only be used once.

Documentation: https://stripe.com/docs/api/curl#create_pii_token

CURL Command

curl https://api.stripe.com/v1/tokens \
   -u STRIPE_SECRET_KEY: \
   -d pii[personal_id_number]=000000000 \
   -X POST

Node.js Example

var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node6_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node6_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node6_linux32');
    } else {
        var chilkat = require('chilkat_node6_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node6_macosx');
}

function chilkatExample() {

    var rest = new chilkat.Rest();
    var success;

    //  URL: https://api.stripe.com/v1/tokens
    var bTls = true;
    var port = 443;
    var bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success !== true) {
        console.log("ConnectFailReason: " + rest.ConnectFailReason);
        console.log(rest.LastErrorText);
        return;
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    rest.AddQueryParam("pii[personal_id_number]","000000000");

    var strResponseBody = rest.FullRequestFormUrlEncoded("POST","/v1/tokens");
    if (rest.LastMethodSuccess !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    var jsonResponse = new chilkat.JsonObject();
    jsonResponse.Load(strResponseBody);

    var id;
    var object;
    var client_ip;
    var created;
    var livemode;
    var type;
    var used;

    id = jsonResponse.StringOf("id");
    object = jsonResponse.StringOf("object");
    client_ip = jsonResponse.IsNullOf("client_ip");
    created = jsonResponse.IntOf("created");
    livemode = jsonResponse.BoolOf("livemode");
    type = jsonResponse.StringOf("type");
    used = jsonResponse.BoolOf("used");

}

chilkatExample();

Sample JSON Response Body

{
  "id": "pii_1BnETKGswQrCoh0XMUBp4DiD",
  "object": "token",
  "client_ip": null,
  "created": 1516662782,
  "livemode": false,
  "type": "pii",
  "used": false
}