SDKs / Libraries

We maintain libraries in popular scripting languages to make it easy to build on top of PassNinja. You can find the source code for these here:

  1. PassNinja Python library
  2. PassNinja Ruby gem
  3. PassNinja NPM package
  4. PassNinja Swift library
  5. PassNinja Java package
  6. PassNinja C# package
  7. PassNinja PHP Composer package

Installation

You can find the installation commands for each of these below.

pip install passninja

Authentication

Initialize the PassNinja client with your API credentials. You can find your API key and Account ID in your account dashboard.

import passninja account_id = '<YOUR_ACCOUNT_ID>' api_key = '<YOUR_API_KEY>' pass_ninja_client = passninja.PassNinjaClient( account_id, api_key )

List Pass Templates

Retrieve a list of all pass templates for your account. (for more information check the API Reference)

pass_templates = pass_ninja_client.pass_templates.find() for template in pass_templates: print(f"{template.id}: {template.name}") print(f" Issued: {template.issuedPassCount}") print(f" Installed: {template.installedPassCount}")

Get Pass Template

Retrieve a specific pass template by its ID. (for more information check the API Reference)

template = pass_ninja_client.pass_templates.get('<YOUR_PASS_TYPE>') print(f"Template: {template.name}") print(f"Platform: {template.platform}") print(f"Style: {template.style}")

Create a Pass

Create a new pass for a given pass template with specified field values. (for more information check the API Reference)

simple_pass_object = pass_ninja_client.passes.create( '<YOUR_PASS_TYPE>', { 'member.level': 'silver', 'discount': '50%', 'member.name': 'John' } ) print(simple_pass_object.serialNumber)

List Passes

Retrieve a list of passes for a given pass template. (for more information check the API Reference)

passes_for_template = pass_ninja_client.passes.find('<YOUR_PASS_TYPE>') print(passes_for_template)

Get a Pass

Retrieve a specific pass by its pass type and serial number. (for more information check the API Reference)

detailed_pass_object = pass_ninja_client.passes.get( '<YOUR_PASS_TYPE>', '<SERIAL_NUMBER>' ) print(detailed_pass_object)

Decrypt a Pass

Decrypt a pass payload using its pass type and encrypted payload. (for more information check the API Reference)

decrypted_pass = pass_ninja_client.passes.decrypt( '<YOUR_PASS_TYPE>', '55166a9700250a8c51382dd16822b0c7...' ) print(decrypted_pass)

Patch a Pass

Partially update a pass. Only the fields provided will be updated; other fields retain their existing values. (for more information check the API Reference)

updated_pass = pass_ninja_client.passes.patch( '<YOUR_PASS_TYPE>', '<SERIAL_NUMBER>', { 'member.name': 'Ted' } ) print(updated_pass)

Update a Pass

Fully update a pass with new field values. All fields must be provided. (for more information check the API Reference)

updated_pass = pass_ninja_client.passes.put( '<YOUR_PASS_TYPE>', '<SERIAL_NUMBER>', { 'member.level': 'gold', 'discount': '100%', 'member.name': 'John' } ) print(updated_pass)

Delete a Pass

Delete a pass by its pass type and serial number. (for more information check the API Reference)

deleted_serial = pass_ninja_client.passes.delete( '<YOUR_PASS_TYPE>', '<SERIAL_NUMBER>' ) print(deleted_serial)