Looking for information/assistance on setting up API

slosanowych
New Contributor

We would like to access our ST data using API.  Unfortunately this is something we are not entirely familiar with.  Is there anyone out there using API to pull data into a data repository, create reports, etc?  I am stuck on the actual set up.  Is this something that can be done locally on a SQL server?  Would we need to get a 3rd party involved or purchase a program to use for this?  I may be asking the wrong questions considering this is one of those "you don't know what you don't know" situations but hopefully this gets my point across.  Any information would be HUGELY appreciated.  Documentation, screenshots, links, really anything that could help.  I checked out the info provided by ST which is helpful but not quite what I need to get things to click for me.  Thank you in advance!

1 ACCEPTED SOLUTION

elliot_e
New Contributor

 

Hello there, we've been using the API for quite a while now and I'd be happy give you my thoughts. 

First off, getting data from a REST API like the ServiceTitan API requires some scripting language to make the request to ServiceTitan's servers and move the data into a database or flat file (csv). Our pipeline consists of Python or Javascript, but almost every program has a package/library to make the requests easier. If you don't have strong programming skills, then I would look at providers like Zapier, or other general pipeline services like Airbyte, Hevo, Pipedream. I haven't personally used any of these 3rd parties, but I know they are popular in other industries. Unfortunately, as far as I've found, there is no way to automatically ingest data from an API directly into a database without some intermediate system orchestrating the data movement.

In general, if you don't have the time, experience, and the personal motivation to build a custom solution, I'd recommend using a low/no-code solution like I listed above. They can get expensive at scale but will certainly save you time trying to learn all of the intricacies of any particular coding language.
---
Below I'll give you the basics for getting data into Python, but similar patterns exist for other languages:

STEP 0: Setting up a python environment 😱

This is a VERY basic steps
1. Install Python from Python.org (make sure you add it to your PATH if on windows)
2. Install requests package 

 

pip install requests

 

3. Install VSCode for running python files
4. Create a folder and open in VSCode

 

NOTE: If any of this is unfamiliar or frustrating, I'd look into the 3rd Party Services

 

STEP 1: Getting the authorization details
You need to gather all of the authentication/authorization details from different parts of ServiceTitan

 

The link below will take you through the steps to get all of this set up.

 

Once this is all complete you will get:
CLIENT_ID - Find in Settings > Integrations > API Application Access > [App Name] > Edit
CLIENT_SECRET - Generated one time with CLIENT ID,
APP_ID - Found in developers portal app definition
APP_KEY - Found in developers portal app definition
TENANT_ID - Found in developers portal app definition and integration settings

 

These will look something like to data below

 

{
   "CLIENT_ID": "cid.hhmdjd1jk9nqwertyr5cl6t5u5r5",
   "CLIENT_SECRET": "cs2.yjnblmqpfiuzjyqwerty5gc28a35qabzo1qsss2l3fll5st64tgrxjxz",
   "APP_ID": "12abc346skeg",
   "APP_KEY": "ak1.qey12fgjhnch03lsm",
   "TENANT_ID": "1234567890",
}​

 

 

STEP 2: Making the Request (Python)
Getting an Authorization Token and making a request

 

import requests

# Fill in each of these variables and they will
CLIENT_ID = ""
CLIENT_SECRET = ""
APP_KEY = ""
TENANT_ID = ""

# --- GETTING YOUR AUTH TOKEN ----
url = "https://auth.servicetitan.io/connect/token"

payload = f"grant_type=client_credentials&client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}"
headers = {"Content-Type": "application/x-www-form-urlencoded"}

response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
token = response['access_token']

# --- GETTING DATA FROM THE ESTIMATES ENDPOINT ----

url = f"https://api.servicetitan.io/sales/v2/tenant/{TENANT_ID}/estimates"

querystring = {"pageSize":"100","active":"true","soldAfter":"2022-09-28T00:00:00Z","page":"1"}

payload = ""
headers = {
    "Authorization": token # this is the token you request above,
    "ST-App-Key": APP_KEY # one of the items you got from servicetitan above
}

response = requests.request("GET", url, data=payload, headers=headers, params=querystring)

print(response.json())

 

 

STEP 3: Parsing the Data and upload to database
Because the data format is in a nested JSON format, you may need to do additional processing to get it all into a more tabular format. I personally like to use the `pandas` package in python, but you may be perfectly happy with other methods. Once it is cleaned to your requirements, you'll want to upload it to your database using connectors (many exist for python and other languages) or you can save to a csv and upload with a different program.
---
I've also created a python package servicepytan that makes it a little simpler to retrieve data from the ServiceTitan and if you decide to go down that path, I'd be happy to help in more detail.

If you want to explore the ServiceTitan API with a more friendly interface I could recommend using a tool like Postman or Insomnia for testing your requests to make sure they're correct. They also generate sample code in your language of choice (its how I made the code above).

 

I hope this at least gets you pointed in the right direction.
 
Elliot Palmer
The Eco Plumbers






View solution in original post

6 REPLIES 6

PamDuffy-PCG
ServiceTitan Certified Provider
ServiceTitan Certified Provider

What exactly are you trying to create; can you describe an example end result? I know you say reports, but can you describe in greater detail one of the reports you'd like to create with API data? 

If you aren't familiar with making API requests, coding in Python and/or JSON, then I would absolutely look to a 3rd party.

 

---
Pam Duffy, Powerhouse Consulting Group
ServiceTitan Certified Coach + ServiceTitan Certified Marketer + Zapier Certified Expert

JessicaSmith
ServiceTitan Certified Administrator
ServiceTitan Certified Administrator

@PamDuffy-PCG is this something you can help with?


Jessica Woodruff Smith, LadyTitans Co-Founder & Process Manager at AirWorks Solutions

sjaeger
ServiceTitan Certified Administrator
ServiceTitan Certified Administrator

We have not started to use the API interface yet, other than Zapier.  We have an in-house IT person who has some experience with API's and even he wanted to consult a third party before he started down that path.  So I would suggest a 3rd party!

elliot_e
New Contributor

 

Hello there, we've been using the API for quite a while now and I'd be happy give you my thoughts. 

First off, getting data from a REST API like the ServiceTitan API requires some scripting language to make the request to ServiceTitan's servers and move the data into a database or flat file (csv). Our pipeline consists of Python or Javascript, but almost every program has a package/library to make the requests easier. If you don't have strong programming skills, then I would look at providers like Zapier, or other general pipeline services like Airbyte, Hevo, Pipedream. I haven't personally used any of these 3rd parties, but I know they are popular in other industries. Unfortunately, as far as I've found, there is no way to automatically ingest data from an API directly into a database without some intermediate system orchestrating the data movement.

In general, if you don't have the time, experience, and the personal motivation to build a custom solution, I'd recommend using a low/no-code solution like I listed above. They can get expensive at scale but will certainly save you time trying to learn all of the intricacies of any particular coding language.
---
Below I'll give you the basics for getting data into Python, but similar patterns exist for other languages:

STEP 0: Setting up a python environment 😱

This is a VERY basic steps
1. Install Python from Python.org (make sure you add it to your PATH if on windows)
2. Install requests package 

 

pip install requests

 

3. Install VSCode for running python files
4. Create a folder and open in VSCode

 

NOTE: If any of this is unfamiliar or frustrating, I'd look into the 3rd Party Services

 

STEP 1: Getting the authorization details
You need to gather all of the authentication/authorization details from different parts of ServiceTitan

 

The link below will take you through the steps to get all of this set up.

 

Once this is all complete you will get:
CLIENT_ID - Find in Settings > Integrations > API Application Access > [App Name] > Edit
CLIENT_SECRET - Generated one time with CLIENT ID,
APP_ID - Found in developers portal app definition
APP_KEY - Found in developers portal app definition
TENANT_ID - Found in developers portal app definition and integration settings

 

These will look something like to data below

 

{
   "CLIENT_ID": "cid.hhmdjd1jk9nqwertyr5cl6t5u5r5",
   "CLIENT_SECRET": "cs2.yjnblmqpfiuzjyqwerty5gc28a35qabzo1qsss2l3fll5st64tgrxjxz",
   "APP_ID": "12abc346skeg",
   "APP_KEY": "ak1.qey12fgjhnch03lsm",
   "TENANT_ID": "1234567890",
}​

 

 

STEP 2: Making the Request (Python)
Getting an Authorization Token and making a request

 

import requests

# Fill in each of these variables and they will
CLIENT_ID = ""
CLIENT_SECRET = ""
APP_KEY = ""
TENANT_ID = ""

# --- GETTING YOUR AUTH TOKEN ----
url = "https://auth.servicetitan.io/connect/token"

payload = f"grant_type=client_credentials&client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}"
headers = {"Content-Type": "application/x-www-form-urlencoded"}

response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
token = response['access_token']

# --- GETTING DATA FROM THE ESTIMATES ENDPOINT ----

url = f"https://api.servicetitan.io/sales/v2/tenant/{TENANT_ID}/estimates"

querystring = {"pageSize":"100","active":"true","soldAfter":"2022-09-28T00:00:00Z","page":"1"}

payload = ""
headers = {
    "Authorization": token # this is the token you request above,
    "ST-App-Key": APP_KEY # one of the items you got from servicetitan above
}

response = requests.request("GET", url, data=payload, headers=headers, params=querystring)

print(response.json())

 

 

STEP 3: Parsing the Data and upload to database
Because the data format is in a nested JSON format, you may need to do additional processing to get it all into a more tabular format. I personally like to use the `pandas` package in python, but you may be perfectly happy with other methods. Once it is cleaned to your requirements, you'll want to upload it to your database using connectors (many exist for python and other languages) or you can save to a csv and upload with a different program.
---
I've also created a python package servicepytan that makes it a little simpler to retrieve data from the ServiceTitan and if you decide to go down that path, I'd be happy to help in more detail.

If you want to explore the ServiceTitan API with a more friendly interface I could recommend using a tool like Postman or Insomnia for testing your requests to make sure they're correct. They also generate sample code in your language of choice (its how I made the code above).

 

I hope this at least gets you pointed in the right direction.
 
Elliot Palmer
The Eco Plumbers






Hi Elliot, 
I am working to achieve some functionality here for an app we are building. Would it be okay to compare some notes and ask a few questions? I used your servicepytan with success, and I am looking to integrate some webhooks using google Cloud function/run and other google apps where I am trying to call the ST API. 

Happy to share what I have and maybe get some advice on how to go about making a few functions work. I connected with you on Linkedin. Cheers. 

TianaMay
New Contributor II

After doing a bit of digging I found a page that may be helpful for you!

https://help.servicetitan.com/how-to/get-started-with-apidev-portal-v2

This page shows you how you can get started with our dev portal! 

Looks like you will want to send an email to integrations@servicetitan.com to get assistance in creating a custom API!  Hope this is helpful!