Manual

Accessing Pogi API Calls with Python 3

Chapter 1: Introduction
Chapter 2: Authenticating with the Pogi Server
Chapter 3: Get Inventory History List
Chapter 4: Retrieving Individual Tag information
Chapter 5: Deleting a Tag
Chapter 6: Adding a Tag into the Inventory
Chapter 7: Editing a Tag in the Inventory
Chapter 1: Introduction

The Pogi server can be accessed through REST API for integration with other applications. This Reference Manual will show you how the Pogi API can be utilized in Python 3 applications.

The sample code can be checked in the public SimplyRFID github repository. The Pogi APIs can also be tested directly using the Insomnia Workspace application. The Insomnia export file can be downloaded from the Pogi API - Insomnia workspace repository or directly imported through the URL https://raw.githubusercontent.com/simplyrfid-dev/pogi-api-insomnia-workspace/main/pogi-api-insomnia-workspace.json

Prerequisites

The following will be required in order to call Pogi API calls in Python 3.

  1. Python3 and pip3 installed
  2. Python Request library installed

To start the interpreter, run python3 from the command line

% python3

Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Chapter 2: Authenticating with the Pogi Server

The Pogi API Calls can only be requested with a valid authentication token. The user will need a user ID and a password for the Pogi server authentication. This usually comes from the Welcome Email that you've received or you can also create a new user through the User Management Page of the Pogi Server. This can then be used to be inserted in the following variables.

pogi_url = 'https://www.-.com:7000' # Insert your Pogi server URL here
user_id = ""  # Insert your Pogi user ID here
user_pwd = "" # Insert your Pogi password here

Parameters for the token-get API call can be checked in the Login Authentication API CALLS chapter of the SimplyRFID Pogi API Manual. Shown below is the code snippet for requesting a token.

# POST auth
token_rs = requests.post(pogi_url, data={ "op": "token-get", "userId": user_id, "password": user_pwd })

# Check the return status, and print the response text
if (token_rs.status_code == 200): 
  print(token_rs.text)
else:
  print('Something went wrong')

The rest of the examples assumes that token is stored in a variable named token. For web-applications, it is not necessary to store the token, this is passed by the browser to the server via cookies. The example below shows how we can check the cookie using Python.

print(token_rs.headers['Set-Cookie'])
Chapter 3: Get Inventory History List

The JSON request is first assembled to query tag history before sending a fetch request. Parameters for the history API call can be checked in the Web API Calls chapter of the SimplyRFID Pogi API Manual.

inventory_params = {
  "op": "history",
  "token": token,
  "fromDate": "",
  "fromTime": "",
  "toDate": "",
  "toTime": "",
  "marker": "",
  "event": "present",
  "zone": "",
  "limit": 15,
  "offSet": 0,
  "currentLocation": "on",
  "namedOnly": "",
  "tagAssetSearchType": "tag",
  "tagAndAssetSearchType": "tag",
  "tagAndAsset": "",
  "orderColumn": "update_date",
  "orderDirection": "DESC"
}

The history list is then requested on the following code snippets

inventory_rs = requests.post(pogi_url, data=inventory_params)
# Check the return status, and print the response text
if (inventory_rs.status_code == 200):
  print(inventory_rs.text)
else:
  print('Something went wrong')

The data count and number of return items is printed by the following snippet.

print(inventory_rs.json()['count'])    
print(len(inventory_rs.json()['data']))

The search result list is printed by looping through it.

for item in inventory_rs.json()['data']:
  print("Tag: {}; Name: {}".format(item['tag_id'], item['name']))
Chapter 4: Retrieving Individual Tag information

In the following chapters, operations for directly manipulating the tags is demonstrated. All API used in here can be checked in the ID API Calls chapter of the Pogi API Manual.

Individual tag information can be retrieved from the Pogi server by using the id-get API call.

# POST request
payload = {
  "op": "id-get",
  "token": token,
  "tag": "000000000000000000000000"
}
id_get_rs = requests.post(pogi_url, data=payload)    
# Check the return status, and print the response text
if (id_get_rs.status_code == 200):
  print(id_get_rs.json())
else:
  print('Something went wrong')

Once retrieved, the result is printed as follows.

print('id-get returned {} result/s'.format(len(id_get_rs.json())))
if len(id_get_rs.json()) > 0:
  data = id_get_rs.json()[0]
  print('Tag: {}; Location: {}'.format(data['tag_id'], data['zone']))
Chapter 5: Deleting a Tag

The tag can be deleted from the inventory through these two steps. The first step is to make sure that the tag to be deleted has no deleted status on it by using the id-undelete API call.

# POST request
payload = {
  "op": "id-undelete",
  "token": token,
  "tagId": "000000000000000000000000"
}
id_undelete_rs = requests.post(pogi_url, data=payload)
# Check the return status, and print the response text
if (id_undelete_rs.status_code == 200):
  print(id_undelete_rs.json())
else:
  print('Something went wrong')

The tag can then be deleted using the id-delete API call.

# POST request
payload = {
  "op": "id-delete",
  "token": token,
  "tagId": "000000000000000000000000"
}
id_delete_rs = requests.post(pogi_url, data=payload)
# Check the return status, and print the response text
if (id_delete_rs.status_code == 200):
  print(id_delete_rs.json())
else:
  print('Something went wrong')
Chapter 6: Adding a Tag into the Inventory

Tags can be added to the inventory through the id-add API call. The payload contains the tag information that will be added into the inventory.

# POST request
payload = {
  "op": "id-add",
  "token": token,
  "tagId": "000000000000000000000000",
  "external_id": "Asset ID",
  "name": "QuickTag Demo",
  "zone": "Laboratory"
}
id_add_rs = requests.post(pogi_url, data=payload)

The status after adding the tag can then be checked as follows.

# Check the return status, and print the response text
if (id_add_rs.status_code == 200):
  print(id_add_rs.json())
else:
  print('Something went wrong')
Chapter 7: Editing a Tag in the Inventory

Tag information can be edited the inventory through the id-update API call. The payload contains the new tag information.

# POST request
payload = {
  "op": "id-update",
  "token": token,
  "tagId": "000000000000000000000000",
  "external_id": "Asset ID Updated",
  "name": "QuickTag Demo Updated",
  "zone": "Laboratory"
}
id_update_rs = requests.post(pogi_url, data=payload)

The status after editing the tag can then be checked as follows.

# Check the return status, and print the response text
if (id_update_rs.status_code == 200):
  print(id_update_rs.json())
else:
  print('Something went wrong')

Go RFID for just $99/mo

Includes Wave app, CS108 RFID handheld, Pogi data server access, our starter kit of RFID tags, and an iPod Touch.

Pay just $99/month plus a one-time charge for the iPod of $250. You may provide your own iOS 13 (or later) device in place of the iPod. The CS108 RFID handheld remains the property of SimplyRFiD if you cancel service. You may pre-pay the year for $990 (2 free months).

Get Started