@passninja/passninja-js

PassNinja pass creation helper library.

Usage no npm install needed!

<script type="module">
  import passninjaPassninjaJs from 'https://cdn.skypack.dev/@passninja/passninja-js';
</script>

README

passninja-js

Use passninja-js as an ES module.

Contents

Installation

Use npm or yarn to install the passninja-js module:

npm install @passninja/passninja-js

Usage

PassNinjaClient

This function returns a newly created PassNinjaClient object. Make sure to pass your user credentials to make any authenticated requests.

const {PassNinjaClient} = require('@passninja/passninja-js');

const accountId = '**your-account-id**';
const apiKey = '**your-api-key**';

const passNinjaClient = new PassNinjaClient(accountId, apiKey);

We’ve placed our demo user API credentials in this example. Replace it with your actual API credentials to test this code through your PassNinja account and don't hesitate to contact PassNinja with our built in chat system if you'd like to subscribe and create your own custom pass type(s).

For more information on how to use passninja-js once it loads, please refer to the PassNinja JS API reference

PassNinjaClientMethods

This library currently supports methods for creating, getting, updating, and deleting passes via the PassNinja api. The methods are outlined below. Note that each method returns a promise.

Create

const simplePassObject = await passNinjaClient.pass.create(
  'demo.coupon', // passType
  {discount: '50%', memberName: 'John'} // passData
);
console.log(simplePassObject.url);
console.log(simplePassObject.passType);
console.log(simplePassObject.serialNumber);

Get

const detailedPassObject = await passNinjaClient.pass.get(
  'demo.coupon', // passType
  '840a0562-f22d-4ecf-a2d7-9ac785bed8e4' // serialNumber
);

Update

const simplePassObject = await passNinjaClient.pass.put(
  'demo.coupon', // passType
  '840a0562-f22d-4ecf-a2d7-9ac785bed8e4', // serialNumber
  {discount: '100%', memberName: 'Ted'} // passData
);

Delete

const deletedPassSerialNumber = await passninja.pass.delete(
    'demo.coupon', // passType,
    '840a0562-f22d-4ecf-a2d7-9ac785bed8e4' // serialNumber
);
console.log(`Pass deleted. serial_number: ${deletedPassSerialNumber})); })();

Script Tag

Manually add the passninja-js script tag to the <head> of each page on your site in order to use PassNinjaClient.

<!-- Somewhere in your site's <head> -->
<script src="https://js.passninja.com/v1" async></script>

Examples

Feel free to browse the Examples Folder for implementations

TypeScript support

This package includes TypeScript declarations for passninja-js. We support projects using TypeScript versions >= 3.1.

Documentation