This repository was archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapicallerscript.py
More file actions
82 lines (66 loc) · 2.36 KB
/
apicallerscript.py
File metadata and controls
82 lines (66 loc) · 2.36 KB
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
#!usr/bin/env python
import requests
import json
def API1(innumbers):
URL='api'.format(innumbers)#string formatting needed {}.format()
headers = {'Authorization':'Basic token'}
response = requests.get(URL,auth=('user,pass'))
if response.status_code != 200:
print(response.status_code)
# #raise ApiError('Error occured.Code: {}'.format(response.status_code))
#return False
else:
output = response.json()
#print(output)
try:
partyid = output['items'][0]['PartyId']#handle exception for KeyError
contactname = output['items'][0]['ContactName']
return partyid,contactname
except KeyError:
print('No matching Key')
return False
def API2(innumbers):
URL='api'.format(innumbers)
headers = {'Authorization':'Basic token'}
response = requests.get(URL,auth=('user,pass'))
if response.status_code != 200:
print(response.status_code)
#raise ApiError('Error occured.Code: {}'.format(response.status_code))
#return False
else:
output = response.status_code
try:
partyid = output['items'][0]['PartyId']#handle exception for KeyError
contactname = output['items'][0]['PrimaryContactName']
return partyid,contactname
except KeyError:
print('No matching Key')
return False
def API3(partyid,contactname):
URL='api'
payload = {"ActivityFunctionCode" : "TASK","Subject" : "Test2",
"AccountId": 300000001917986,"ActivityTypeCode":"CALL","ActivityPartialDescription":"Testing",
"CallStatus_c": "OFF"}
payload['AccountId'] = partyid
payload['Subject']='missed call from'+' '+contactname
headers = {'Authorization':'Basic token'}
response = requests.post(URL,json=payload,auth=('user,pass'))
if response.status_code != 201:
print(response.status_code)
#raise ApiError('Error occured.Code: {}'.format(response.status_code))
else:
output = response.json()
print(response.status_code)
def API4(numberR):
URL='api'
payload = {"ActivityFunctionCode" : "TASK","Subject" : "Test2","ActivityTypeCode":"CALL",
"ActivityPartialDescription":"Testing","CallStatus_c": "OFF"}
payload['Subject']='missed call from'+' '+numberR
headers = {'Authorization':'Basic token'}
response = requests.post(URL,json=payload,auth=('user,pass'))
if response.status_code != 201:
print(response.status_code)
#raise ApiError('Error occured.Code: {}'.format(response.status_code))
else:
output = response.json()
print(response.status_code)