Package: pyonfleet
Onfleet Python WrapperRead this document in another language:正體中文EspañolVisit our blog post on theAPI wrapper projectto learn more about our initiatives.If you have any questions, please reach us by submitting an issuehereor contactsupport@onfleet.com.Table of contentsTable of contentsSynopsisInstallationUsageUnit testing using DockerThrottlingResponsesSupported CRUD operationsGET RequestsExamples ofget()Examples ofget(param)Examples ofgetByLocationPOST RequestsExamples ofcreate()PUT RequestsExamples ofupdate()Examples ofinsertTask()DELETE RequestsExamples ofdeleteOne()SynopsisThe Onfleet Python library provides convenient access to the Onfleet API.Installationpip install pyonfleetUsageBefore 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 theOnfleet dashboard.To authenticate, you will also need to create a file named.auth.jsonunder your working directory –this is where you will store your API credentials.The format of.auth.jsonis shown below:{"API_KEY":"<your_api_key>"}You can also opt in to not store your API key here and pass it as param toOnfleet:fromonfleetimportOnfleet# Option 1 - Recommendedonfleet_api=Onfleet()# Using the .auth.json file# Option 2onfleet_api=Onfleet(api_key="<your_api_key>")# Without the .auth.json fileAnother optional parameter forOnfleetiscustom_headerswhere you can pass in headers to be applied to all requests. For example:onfleet_api=Onfleet(custom_headers={"<header_name>":"<header_value>"})Once theOnfleetobject is created, you will get access to all the API endpoints as documented in theOnfleet API documentation.Unit testing using Dockerdocker-compose up --buildThrottlingRate limiting is enforced by the API with a threshold of 20 requests per second across all your organization's API keys. Learn more about ithere.ResponsesResponses of this library are instances ofResponsefrom therequestslibrary.Supported CRUD operationsHere are the operations available for each entity:EntityGETPOSTPUTDELETEAdmins/Administratorsget()create(body={})matchMetadata(body={})update(id, body={})deleteOne(id)Containersget(workers=id)get(teams=id)get(organizations=id)xupdate(id, body={})xDestinationsget(id)create(body={})matchMetadata(body={})xxHubsget()create(body={})update(id, body={})xOrganizationget()get(id)xinsertTask(id, body={})xRecipientsget(id)get(name='')get(phone='')create(body={})matchMetadata(body={})update(id, body={})xTasksget(queryParams={})get(id)get(shortId=id)create(body={})clone(id)forceComplete(id)batch(body={})autoAssign(body={})matchMetadata(body={})update(id, body={})deleteOne(id)Teamsget()get(id)getWorkerEta(id, queryParams={})getTasks(id, queryParams={})create(body={})autoDispatch(id, body={})update(id, body={})insertTask(id, body={})deleteOne(id)Webhooksget()create(body={})xdeleteOne(id)Workersget()get(id)get(queryParams={})getByLocation(queryParams={})getSchedule(id)getTasks(id, queryParams={})create(body={})setSchedule(id, body={})matchMetadata(body={})update(id, body={})insertTask(id, body={})deleteOne(id)GET RequestsTo get all the documents within an endpoint:get()Examples ofget()onfleet_api.workers.get()onfleet_api.workers.get(queryParams="")Optionally you can usequeryParamsfor some certain endpoints.Refer back toAPI documentationfor endpoints that support query parameters.# Option 1onfleet_api.workers.get(queryParams={"phones":"<phone_number>"})# Option 2onfleet_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 ofget(param)onfleet_api.workers.get(id="<24_digit_ID>")onfleet_api.workers.get(id="<24_digit_ID>",queryParams={"analytics":"true"})onfleet_api.tasks.get(shortId="<shortId>")onfleet_api.recipients.get(phone="<phone_number>")onfleet_api.recipients.get(name="<name>")onfleet_api.containers.get(workers="<worker_ID>")onfleet_api.containers.get(teams="<team_ID>")onfleet_api.containers.get(organizations="<organization_ID>")Note:don't use Python-styleTrueandFalsefor boolean values - supply these as strings like"true"or"false".To get a driver by location, use thegetByLocationfunction:getByLocation(queryParams="<location_params>")Examples ofgetByLocationlocation_params={"longitude":"-122.4","latitude":"37.7601983","radius":"6000",}onfleet_api.workers.getByLocation(queryParams=location_params)POST RequestsTo create a document within an endpoint:create(body="<data>")Examples ofcreate()data={"name":"John Driver","phone":"+16173428853","teams":["<team_ID>","<team_ID> (optional)","..."],"vehicle":{"type":"CAR","description":"Tesla Model S","licensePlate":"FKNS9A","color":"purple",},}onfleet_api.workers.create(body=data)Extended POST requests includeclone,forceComplete,batchCreate,autoAssignon theTasksendpoint;setScheduleon theWorkersendpoint;autoDispatchon theTeamsendpoint; andmatchMetadataon all supported entities. For instance:onfleet_api.tasks.clone(id="<24_digit_ID>")onfleet_api.tasks.forceComplete(id="<24_digit_ID>",body="<data>")onfleet_api.tasks.batchCreate(body="<data>")onfleet_api.tasks.autoAssign(body="<data>")onfleet_api.workers.setSchedule(id="<24_digit_ID>",body="<data>")onfleet_api.teams.autoDispatch(id="<24_digit_ID>",body="<data>")onfleet_api.<entity_name_pluralized>.matchMetadata(body="<data>")For more details, check our documentation onclone,forceComplete,batchCreate,autoAssign,setSchedule,matchMetadata, andautoDispatch.PUT RequestsTo update a document within an endpoint:update(id="<24_digit_ID>",body="<data>")Examples ofupdate()new_data={"name":"Jack Driver",}onfleet_api.workers.update(id="<24_digit_ID>",body=new_data)Examples ofinsertTask()onfleet_api.workers.insertTask(id="<24_digit_ID>",body="<data>")DELETE RequestsTo delete a document within an endpoint:deleteOne(id="<24_digit_ID>")Examples ofdeleteOne()onfleet_api.workers.deleteOne(id="<24_digit_ID>")Go totop.