Code examples from the September 7th Logentries REST API Webinar
Created
September 7, 2016 13:24
-
-
Save jbuchanan-r7/c40be611b1ea531c0745e23493bc0377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
# Logentries REST API POST New User Example | |
# Documentation: https://docs.logentries.com/docs/post-user-new-user | |
resourceId = 'YOUR ACCOUNT RESOURCE ID GOES HERE' | |
apiKey = 'YOUR API KEY GOES HERE' # This must be the owner key | |
uri = "management/accounts/%s/users" % resourceId | |
usersToAdd = ( | |
{ | |
'email': 'example+00@gmail.com', | |
'first_name': 'first00', | |
'last_name': 'last00' | |
}, | |
{ | |
'email': 'example+01@gmail.com', | |
'first_name': 'first01', | |
'last_name': 'last01' | |
}, | |
{ | |
'email': 'example+02@gmail.com', | |
'first_name': 'first02', | |
'last_name': 'last02' | |
} | |
) | |
def create_user(email, first_name, last_name): | |
body = { | |
"user": { | |
"email": email, | |
"first_name": first_name, | |
"last_name": last_name | |
} | |
} | |
url = "https://rest.logentries.com/" + uri | |
headers = { | |
'x-api-key': apiKey, | |
"Content-Type": "application/json" | |
} | |
r = requests.post(url, data=json.dumps(body, separators=(',', ':')), headers=headers) | |
print r.status_code, r.content | |
def start(): | |
for user in usersToAdd: | |
create_user(user['email'],user['first_name'],user['last_name']) | |
if __name__ == '__main__': | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment