-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clio.js
136 lines (119 loc) · 5.03 KB
/
Clio.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function assignMatter(matterID, field_id, custom_id){
var cache = CacheService.getUserCache();
if (custom_id == 'missing'){
Logger.log("Made It")
// Payload adds a new custom field with the appropriate case number
var payload = {
"data": {
"custom_field_values": [{
"custom_field" : {"id" : field_id},
"value" : cache.get('CaseNumber')
}]
}
}
} else {
// Payload updates an existing custom field with the appropriate case number
var payload = {
"data": {
"custom_field_values": [{
"id" : custom_id,
"custom_field" : {"id" : field_id},
"value" : cache.get('CaseNumber')
}]
}
};
Logger.log(payload);
};
var strMatter = accessProtectedResource('https://app.clio.com/api/v4/matters/' + matterID + '.json?fields=id,display_number,description,client','patch',{},JSON.stringify(payload),'application/json');
return JSON.parse(strMatter);
}
function createCaseField() {
var userProperties = PropertiesService.getUserProperties();
var payload = {
"data": {
"name": userProperties.getProperty('field_name'),
"parent_type": "Matter",
"field_type": "text_line"
}
};
return accessProtectedResource('https://app.clio.com/api/v4/custom_fields.json','post',{},JSON.stringify(payload),'application/json');
}
function getCaseFieldID(fieldName){
// Deleted fields persist for a time with deleted: true. Must test
var strCaseNumber = accessProtectedResource('https://app.clio.com/api/v4/custom_fields.json?fields=id,field_type,deleted,etag&parent_type=Matter&query=' + fieldName);
var objCaseNumber = JSON.parse(strCaseNumber).data.filter(function(field){return field.deleted==false})[0];
if (objCaseNumber){
return objCaseNumber.id
} else {
strCaseNumber = createCaseField();
return JSON.parse(strCaseNumber).data.id;
}
}
function getContacts(query){
var strContacts = accessProtectedResource('https://app.clio.com/api/v4/contacts.json?fields=id,name&order=name(asc)&query=' + query);
return JSON.parse(strContacts).data
}
function getMatter(CaseFieldID,CaseNumber){
var strMatter = accessProtectedResource('https://app.clio.com/api/v4/matters.json?fields=id,display_number,description,client&custom_field_values[' + CaseFieldID +']=' + CaseNumber);
var objMatter = JSON.parse(strMatter);
var numRecords = objMatter.meta.records
if (numRecords==1){
return objMatter.data[0];
} else if (numRecords==0){
return {'id':'none'}
} else {
return {'id':'duplicates'};
};
}
function getMatters(query){
return JSON.parse(accessProtectedResource(encodeURI('https://app.clio.com/api/v4/matters.json?fields=id,custom_field_values{id,field_name,value},description,display_number,client&query=' + query))).data;
}
function uploadFile(id,link,myFile){
var disposition = myFile.getHeaders()['Content-Disposition'];
var filename = disposition.slice(disposition.indexOf('filename=')+9);
if (filename[0]=='"'){
filename = filename.slice(1,-1)
};
// Gets bucket for file upload
var payload = {
"data": {
"name": filename,
"parent": {
"id" : id,
"type" : "Matter"
},
"external_properties":[{
"name": "link",
"value": link
}]
}
};
var strFileShell = accessProtectedResource(encodeURI('https://app.clio.com/api/v4/documents.json?fields=id,latest_document_version{uuid,put_url,put_headers}'),'post',{},JSON.stringify(payload),'application/json');
var objFileShell = JSON.parse(strFileShell).data;
// Uploads file to AWS bucket
var put_url = objFileShell.latest_document_version.put_url;
var put_headers = {};
objFileShell.latest_document_version.put_headers.forEach(
function(el){
put_headers[el['name']]=el['value'];
}
);
var strFileUpload = UrlFetchApp.fetch(put_url,{'muteHttpExceptions': true,'method':'put','headers': put_headers,'payload':myFile});
// Finalizes file upload and makes it available to Clio front end
var payload = {
"data": {
"uuid": objFileShell.latest_document_version.uuid,
"fully_uploaded" : true
}
};
accessProtectedResource('https://app.clio.com/api/v4/documents/' + objFileShell.id + encodeURI('.json?fields=id,latest_document_version{fully_uploaded}'),'patch',{},JSON.stringify(payload),'application/json');
}
function isDocumentAttached(id,link){
var strDocuments = accessProtectedResource('https://app.clio.com/api/v4/documents.json?matter_id=' + id + '&external_property_name=link&external_property_value=' + link);
var objDocuments = JSON.parse(strDocuments);
if (objDocuments.data.length == 0) {
return 'Missing'
} else {
return 'Uploaded'
}
}