-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteHooks
89 lines (89 loc) · 3.4 KB
/
deleteHooks
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
dynamic_map = Map();
resp = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.getwebhooks0",dynamic_map);
info resp;
sendmail
[
from :zoho.adminuserid
to :zoho.loginuserid
subject :"Response"
message :"Response" + resp
]
responseJsonList = resp.getJSON("response").toJSONList();
for each response in responseJsonList
{
targetURL = response.get("target");
if(targetURL.contains("platform.zoho"))
{
delMap = Map();
delMap.put("id",response.get("id"));
r = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.deletehook",delMap);
message = "Duplicate Hooks removed";
}
else
{
message = "Nothing to do!";
}
}
getmap = {"nameSpace":"premk.acuityscheduling1"};
apiresponse = zoho.crm.invokeConnector("crm.zapikey",getmap);
zapikey = apiresponse.get("response");
debugVal = zoho.crm.getOrgVariable("acuityscheduling1__debug");
if(debugVal = "no")
{
debug = false;
}
else if(debugVal = "yes")
{
debug = true;
}
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.adminuserid
subject :"zapikey"
message :"zapikey" + zapikey + "apiresponse " + apiresponse
]
}
crm_signal_webhook_url = "https://platform.zoho.com/crm/v2/functions/acuityscheduling1.onschedule/actions/execute?auth_type=apikey&zapikey=" + zapikey;
crm_signal_cancel_webhook_url = "https://platform.zoho.com/crm/v2/functions/acuityscheduling1.oncschedule/actions/execute?auth_type=apikey&zapikey=" + zapikey;
crm_signal_res_webhook_url = "https://platform.zoho.com/crm/v2/functions/acuityscheduling1.onrschedule/actions/execute?auth_type=apikey&zapikey=" + zapikey;
scheduledMap = {"triggerEvent":"appointment.scheduled","targetUrl":crm_signal_webhook_url};
canScheduledMap = {"triggerEvent":"appointment.canceled","targetUrl":crm_signal_cancel_webhook_url};
resScheduledMap = {"triggerEvent":"appointment.rescheduled","targetUrl":crm_signal_res_webhook_url};
// for schedule
response = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.createwebhook3",scheduledMap);
ResponseMap = response.get("response").toMap();
webhookid = ResponseMap.get("id");
setResp = zoho.crm.invokeConnector("crm.set",{"apiname":"acuityscheduling1__webhook","value":webhookid});
// for cancel
canResponse = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.createwebhook3",canScheduledMap);
canResponseMap = canResponse.get("response").toMap();
if(response.get("status_code") == '201' || response.get("status_code") == '200')
{
message = message + ", " + "Hooks are created please proceed";
}
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.adminuserid
subject :"Response on Authorization"
message :"response" + response
]
}
canWebHookId = canResponseMap.get("id");
setCanResp = zoho.crm.invokeConnector("crm.set",{"apiname":"acuityscheduling1__canwebhook","value":canWebHookId});
//for reschedule
resResponse = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.createwebhook3",resScheduledMap);
resResponseMap = resResponse.get("response").toMap();
resWebHookId = resResponseMap.get("id");
setResResp = zoho.crm.invokeConnector("crm.set",{"apiname":"acuityscheduling1__reswebhook","value":resWebHookId});
m = Map();
linkResponse = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.getme",m);
linkMap = linkResponse.get("response").toMap();
schedulingPage = linkMap.get("schedulingPage");
schedulingLink = zoho.crm.invokeConnector("crm.set",{"apiname":"acuityscheduling1__clientURL","value":schedulingPage});
return message;