Skip to content

Commit 5a1fc25

Browse files
committed
Added create_user
1 parent a2e88e0 commit 5a1fc25

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

REST_API_v2/Users/list_user_log_entries.py renamed to REST_API_v2/Users/create_user.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,38 @@
2424
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2525
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2626
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
#
28+
# FIXME receiving 2001 - Name cannot be empty
2729

2830
import requests
2931
import json
3032

3133
# Update to match your API key
3234
API_KEY = '3c3gRvzx7uGfMYEnWKvF'
3335

34-
# Update to match the user ID of the user whose log entries you want to GET
35-
USER_ID = 'P9GJP78'
36-
3736
# Update to match your chosen parameters
38-
TIME_ZONE = 'UTC'
39-
SINCE = ''
40-
UNTIL = ''
41-
IS_OVERVIEW = False
42-
INCLUDE = []
37+
NAME = 'Insert user name here'
38+
EMAIL = 'insert_email@here.com'
39+
ROLE = 'user' # Can be one of admin, user, team_responder, limited_user, read_only_user
4340

44-
def list_user_log_entries():
45-
url = 'https://api.pagerduty.com/users/' + USER_ID + '/log_entries'
41+
def create_user():
42+
url = 'https://api.pagerduty.com/users'
4643
headers = {
4744
'Accept': 'application/vnd.pagerduty+json;version=2',
48-
'Authorization': 'Token token=' + API_KEY
45+
'Authorization': 'Token token=' + API_KEY,
46+
'Content-type': 'application/json'
4947
}
5048
payload = {
51-
'time_zone': TIME_ZONE,
52-
'is_overview': IS_OVERVIEW,
53-
'include': INCLUDE
49+
'user': {
50+
'type': 'user',
51+
'name': NAME,
52+
'email': EMAIL,
53+
'role': ROLE
54+
}
5455
}
55-
if SINCE != '':
56-
payload['since'] = SINCE
57-
if UNTIL != '':
58-
payload['until'] = UNTIL
59-
r = requests.get(url, headers=headers, params=json.dumps(payload))
56+
r = requests.post(url, headers=headers, data=json.dumps(payload))
6057
print 'Status Code: ' + str(r.status_code)
6158
print r.json()
6259

6360
if __name__ == '__main__':
64-
list_user_log_entries()
61+
create_user()

0 commit comments

Comments
 (0)