Onfleet's Python API Wrapper Package
Project description
Onfleet Python Wrapper
Visit our blog post on the API wrapper project to learn more about our initiatives.
If you have any questions, please reach us by submitting an issue here or contact support@onfleet.com.
Table of contents
Synopsis
The Onfleet Python library provides convenient access to the Onfleet API.
Installation
pip install pyonfleet
Usage
Before using the API wrapper, you will need to obtain an API key from one of your organization's admins.
Creation and integration of API keys are performed through the Onfleet dashboard.
To authenticate, you will also need to create a file named .auth.json
under your working directory –this is where you will store your API credentials.
The format of .auth.json
is shown below:
{
"API_KEY": "<your_api_key>"
}
You can also opt in to not store your API key here and pass it as param to Onfleet
:
from onfleet import Onfleet
# Option 1 - Recommended
api = Onfleet() # Using the .auth.json file
# Option 2
api = Onfleet(api_key="<your_api_key>") # Without the .auth.json file
Once the Onfleet
object is created, you will get access to all the API endpoints as documented in the Onfleet API documentation.
Throttling
Rate limiting is enforced by the API with a threshold of 20 requests per second across all your organization's API keys. Learn more about it here.
Responses
Responses of this library are instances of Response from the requests
library.
Supported CRUD operations
Here are the operations available for each entity:
Entity | GET | POST | PUT | DELETE |
---|---|---|---|---|
Admins/Administrators | get() | create(body), matchMetadata(body) | update(id, body) | deleteOne(id) |
Containers | get(workers=id), get(teams=id), get(organizations=id) | x | update(id, body) | x |
Destinations | get(id) | create(body), matchMetadata(body) | x | x |
Hubs | get() | create(body) | update(id, body) | x |
Organization | get(), get(id) | x | insertTask(id, body) | x |
Recipients | get(id), get(name), get(phone) | create(body), matchMetadata(body) | update(id, body) | x |
Tasks | get(queryParams), get(id), get(shortId) | create(body), clone(id), forceComplete(id), batch(body), autoAssign(body), matchMetadata(body) | update(id, body) | deleteOne(id) |
Teams | get(), get(id), getWorkerEta(id, queryParams) | create(body), autoDispatch(id, body) | update(id, body), insertTask(id, body) | deleteOne(id) |
Webhooks | get() | create(body) | x | deleteOne(id) |
Workers | get(), get(queryParams), get(id), getByLocation(queryParams), getSchedule(id) | create(body), setSchedule(id, body), matchMetadata(body) | update(id, body), insertTask(id, body) | deleteOne(id) |
GET Requests
To get all the documents within an endpoint:
get()
Examples of get()
api.workers.get()
api.workers.get(queryParams="")
Optionally you can use queryParams
for some certain endpoints.
Refer back to API documentation for endpoints that support query parameters.
# Option 1
api.workers.get(queryParams="phones=<phone_number>")
# Option 2
api.workers.get(queryParams={"phones": "<phone_number>"})
To get one of the document within an endpoint, specify the param that you wish to search by:
get(param="<value>")
Examples of get(param)
api.workers.get(id="<24_digit_ID>")
api.workers.get(id="<24_digit_ID>", queryParams={"analytics": "true"})
api.tasks.get(shortId="<shortId>")
api.recipients.get(phone="<phone_number>")
api.recipients.get(name="<name>")
api.containers.get(workers="<worker_ID>")
api.containers.get(teams="<team_ID>")
api.containers.get(organizations="<organization_ID>")
To get a driver by location, use the getByLocation
function:
getByLocation(queryParams="<location_params>")
Examples of getByLocation
:
location_params = {
"longitude": "-122.4",
"latitude": "37.7601983",
"radius": "6000",
}
api.workers.getByLocation(queryParams=location_params)
POST Requests
To create a document within an endpoint:
create(body="<data>")
Examples of create()
data = {
"name": "John Driver",
"phone": "+16173428853",
"teams": ["<team_ID>", "<team_ID> (optional)", ...],
"vehicle": {
"type": "CAR",
"description": "Tesla Model S",
"licensePlate": "FKNS9A",
"color": "purple",
},
}
api.workers.create(body=data)
Extended POST requests include clone
, forceComplete
, batchCreate
, autoAssign
on the Tasks endpoint; setSchedule
on the Workers endpoint; autoDispatch
on the Teams endpoint; and matchMetadata
on all supported entities. For instance:
api.tasks.clone(id="<24_digit_ID>")
api.tasks.forceComplete(id="<24_digit_ID>", body="<data>")
api.tasks.batchCreate(body="<data>")
api.tasks.autoAssign(body="<data>")
api.workers.setSchedule(id="<24_digit_ID>", body="<data>")
api.teams.autoDispatch(id="<24_digit_ID>", body="<data>")
api.<entity>.matchMetadata(body="<data>")
For more details, check our documentation on clone
, forceComplete
, batchCreate
, autoAssign
, setSchedule
, and matchMetadata
.
PUT Requests
To update a document within an endpoint:
update(id="<24_digit_ID>", body="<data>")
Examples of update()
new_data = {
"name": "Jack Driver",
}
api.workers.update(id="<24_digit_ID>", body=new_data)
Examples of updateSchedule()
api.workers.updateSchedule(id="<24_digit_ID>", body="<data>")
For more details, check our documentation on updateSchedule
Examples of insertTask()
api.workers.insertTask(id="<24_digit_ID>", body="<data>")
DELETE Requests
To delete a document within an endpoint:
deleteOne(id="<24_digit_ID>")
Examples of deleteOne()
api.workers.deleteOne(id="<24_digit_ID>")
Go to top.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyonfleet-1.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00a62a6740742e73dc6170c18a51832da295e23991aef18673eabb254455a558 |
|
MD5 | a8a2f9ac718bd16056842f41dd22d776 |
|
BLAKE2b-256 | 7f85d8d2f344c2c4431de20e5775bc76e57e5de841d547b96fed4841eec5e8c0 |