Skip to content

Instantly share code, notes, and snippets.

@jbuchanan-r7
Created September 7, 2016 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbuchanan-r7/c40be611b1ea531c0745e23493bc0377 to your computer and use it in GitHub Desktop.
Save jbuchanan-r7/c40be611b1ea531c0745e23493bc0377 to your computer and use it in GitHub Desktop.
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