How to use the PII Vault API – Python Edition

Last updated 09/06/2021

Introduction

The purpose of this document is to provide an introduction for Python developers on how to utilize the PII Vault API, along with code examples. This document should be consistent with what is seen in the corresponding repository, which is an open source program to help developers walk through how the API is used.

All requests in the API return a JSON response with some specific fields that make all API responses consistent regardless of what end point is called.

This document assumes the developer has some background in writing code in Python and/or has experience calling REST APIs.

Setup

This accompanying project was set up in Python 3 and it is highly recommended to use the latest version of Python to accomplish using this API.

At the time of this writing, the following entries were made into the requirements.txt file

requests==2.24.0

Requests

This python library will be used to make our HTTP requests to the API.

Accompanying Classes

Several Python classes were written in this project to assist in more mundane tasks of calling the API. This document will explain the points of interest so if a developer decides to write their own classes or methods, they fully understand what to expect.

Call Python Files

The intention of these files is to perform the setup to eventually call the API. It includes steps to request the token needed for authorization, and making the call itself.

GetPolyId.py

This file calls the endpoint at: https://api.piivault.com/api/profiles/GetPolyId

After sending 1 mock profile to the API, the response is printed on screen after running: python GetPolyId.py.

GetPolyIdBulk.py

This file calls the endpoint at: https://api.piivault.com/api/profiles/GetPolyIdBulk

After sending 3 mock profiles to the API, the response is printed on screen after running: python GetPolyIdBulk.py.

Base Python Classes

High level classes meant to help with more redundant tasks to prepare to call the API.

Settings.py

Reads the settings.json file that will contain vital information such as endpoint URLs and API keys.

ApiError.py

Meant to represent a basic error object.

ApiResponse.py

Meant to represent a base API response, send the response JSON through this.

Here is what a base use of this class is meant to look like:

import requests

from Settings import Settings

from ApiResponse import ApiResponse

from Profile import Profile

from ObjectBuilder import ObjectBuilder

# Initialize the setings

settings = Settings()

# Build the request to get the token

request = requests.post(settings.settings_data[“Urls”][“AuthLoginUrl”], json=settings.get_api_auth_data())

# Token request response

response = request.json()

# Object to represent the API response

api_response = ApiResponse()

api_response.ProcessObject(response)

if api_response.success:

# Token granted

else:

print(api_response.error.status)

print(api_response.error.message)

Object Classes

ObjectBuilder.py

Meant to build hardcoded values for demonstration purposes.

ProfileBulk.py

Means to hold multiple Profile objects.

Profile.py

Base profile class.

ProfileAddress.py, ProfileEmail.py, ProfileKey.py, ProfilePhone.py

Classes to be contained with the profile class.

It should be observed

Conclusion

This should get a developer started on how to use Python to call the PII Vault API. To get a full grasp of all of the possible end points with this API, you may consult the following URL: https://api.piivault.com/index.html. This should allow a developer to get started using this API and service to help with anonymizing sensitive data.