Pi Platform APIs
The platform API grants access for Third Party Applications to communicate with the Pi Servers. Information can be requested about Pioneers or transactions that are related with your app deployed on the Pi App Platform, and the Pioneers that use your app.
Table of contents
Making API Calls
Headers and Authorization Methods
This is how the Pi Servers will determine if the request is coming from an approved source. There are two formats depending on the endpoint being requested.
Access Token (Bearer Token)
These API calls require that you provide a Pioneer’s access token to obtain the resource. They are generally related with a Pioneer’s data (e.g: /me). The token is returned from the Pi.Authenticate function of the Pi App Platform SDK.
Those endpoints can be accessed using the following Authorization header:
Example Code:
Server API Key (Authorization Key)
For various reasons, some API calls must be made from the backend or server of your app. To obtain an authorization key for API requests, please see the section of this guide on the Developer Portal.
Those endpoints can be accessed using the following Authorization header:
Example code calling the /payments
endpoint to obtain the information on a payment using the paymentID string:
API Reference
/me
Access a Pioneer’s resource and retrieve the Pioneer’s information.
Authorization method: Access token
Response type: UserDTO
The request will fail (401 HTTP error code) if the token has been tampered with, as a tampered Access token would not belong to any Pioneer.
/payments
Payments are covered in greater detail in the Pi Payment Flow section of this guide. If this is your first implementation of a Pi payment, it’s highly recommended to read that section in addition. It covers how Pi Payments are initiated and completed. This section only covers the API calls.
The APIs for payments all have the base route /payments
. It is important to not create payments using the Platform API. Use the client-side Javascript SDK for this purpose.
Get Information:
Authorization method: Server API Key
Response type: PaymentDTO
Approve a Payment:
This marks a payment as approved within the Pi Server, enabling the Pioneer to approve and submit the transaction to the blockchain. The paymentID
is obtained as a argument of the callback function onReadyForServerApproval
from the Pi App Platform SDK. Read more on that function on the Pi App Platform SDK page. The paymentID
should be passed from your client side to your server side for this call.
Once the paymentID
is on your server side then call the /approve
endpoint using the paymentID
to identify the payment:
Authorization method: Server API Key
Response type: PaymentDTO
Here is the code to call the /approve
endpoint and console.log
the returned PaymentDTO
Complete a Payment:
This marks a payment as completed by proving to the Pi Servers that your app has obtained the payment’s transaction ID (txID). This is the final step in a payment before the payment flow closes and the Pioneer returns to your app. The txID
is obtained through the callback function onReadyForServerCompletion
of the Pi App Platform SDK. Passing that txID
to your server side and using it to call this endpoint will complete a payment.
Don’t forget that
Authorization method: Server API Key
Response type: PaymentDTO
Example Request
Resource Types
There are two resources currently returned by the Pi App Platform API: ‘AuthResults’’ and the PaymentDTO
. In the future, there may be more.