-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
65 lines (54 loc) · 1.83 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Newtonsoft.Json.Linq;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Windows.Forms;
namespace ST_Inspector
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static IRestResponse GetJobData(int jobNum)
{
string requestUrlStart = "jobs/";
string API_KEY = "YOUR_ST_API_KEY";
string requestUrlEnd = "?serviceTitanApiKey=" + API_KEY;
string requestUrlFull = requestUrlStart + jobNum + requestUrlEnd;
string ST_USER = "USER";
string ST_PWD = "PASSWORD";
//new rest client for the ST API
var client = new RestClient("https://api.servicetitan.com/v1");
//auth factor
client.Authenticator = new HttpBasicAuthenticator(ST_USER, ST_PWD);
//initial request
var request = new RestRequest(requestUrlFull, DataFormat.Json);
//server response
IRestResponse response = client.Get(request);
return response;
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void generateButton_Click(object sender, EventArgs e)
{
outputTextBox.Text = "";
int jobNum = Int32.Parse(inputTextBox.Text);
IRestResponse jobData = GetJobData(jobNum);
string content = jobData.Content;
if(content.Contains("does not exist"))
{
outputTextBox.Text = "Job does not exist.";
return;
}
dynamic jData = JObject.Parse(content);
outputTextBox.Text = jData.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}