# Authentication

To access any of the Petro.ai data programmatically, you will need an access token.

# Using the Petro.ai App Token

Petro.ai uses access tokens to associate API calls to a verified Petro.ai account. This keeps your data secure to your system. You will need to configure access to the Petro.ai API before you can use it. Follow these steps:

  1. Create a profile on Petro.ai Portal
  2. From the Settings page, open the API Key Manager
  3. Request an access token using the API Key Manager. You can then add the toekn to the HTTP header in each of your API requests.

To use the Petro.ai API, you will need to have an account on Petro.ai Portal. This associates a user to the API requests that are being generated.


  • Your Petro.ai account must have admin level credentials to request API access.
  • Your organization must have API Access activated on your organization account.
  1. Inside of the Petro Portal, select Settings from the toolbar.
  2. If API access is available, you will see API Keys in the Admin Settings. Click New API Key.
  3. Provide a description for your API Key so that it can be easily identified in the future. .
  4. Copy your App ID and Secret Key for use in your API calls. NOTE: This is the only time you can retrieve the Secret Key.
  5. Your newly created API Key will now be shown in the table. You can enable, disable and delete keys from the table.
  6. When making API calls using your API Key use Basic Auth with your App ID as the username and your Secret Key as the password.
import requests as r
from pprint import pprint

## Using App ID
appid = '7d54ac3f46493ff662f224e1ab2f1642'
apikey = 'b082c84e856987a9cb7ac9500ac54fc9'
url = 'https://yourcompany.petro.ai/api/data'
resp = r.post(url,
    auth = (appid, apikey),
    json = {
        "type": "petron",
        "data": [
                "name": "My Petron!",
                "description": "The first one!"

# Using your JWT

You can temporarily access the Petro.ai API with your user JSON Web Token (JWT) which is valid for 4 hours. To obtain your JWT:

  • Log into your Petro.ai instance in your environment. This will invoke a login into your portal account.
  • Once inside the Petro.ai application open your Dev Tools in Chrome (Ctrl+Shift+I or F12).
  • Navigate to Application > Local Storage and then select your Petro.ai site.

Chrome Devtools

  • Copy the value from the key "petroai-token". Your token will be valid for 4 hours.

Your requests to the API will be a HTTP GET request with a header containing the Bearer token. You will recieve a JSON response from the server with the requested data. You can parameterize this call with a given set of arguments.

Component Description
URL parts This is where you will input the name of the server as well as the collection that you are trying to reach. Use the API documentation below to see the strings used. Usually they will be constructed as api/Wells or api/CompletionDataPoints.
HTTP request header parameters To connect to Petro.ai you will need a bearer token. You can find your token on portal.petro.ai and you'll enter it here as Bearer e5kd4i3gu2tj23e47ke.....
import requests as r
from pprint import pprint

## Enter your JWT Token here
token = ''
headers = {'Authorization': 'Bearer ' + token}
url = 'https://yourcompany.petro.ai/api/data/query'
resp = r.post(url,
    headers = headers,
    json = {
        "type": "petron",
        "query": {},
        "options": { "limit" : 10 }