File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """
3+ Create an API key for your account
4+ """
5+ import getpass
6+ import requests
7+ from urllib .parse import urljoin
8+
9+ username = input ("Username: " )
10+ password = getpass .getpass ()
11+
12+ api_base_url = "https://api.probely.com"
13+ auth_endpoint = urljoin (api_base_url , "enterprise/auth/obtain/" )
14+ keys_endpoint = urljoin (api_base_url , "keys/" )
15+
16+ # Get login token
17+ response = requests .post (auth_endpoint ,
18+ data = {'username' : username , 'password' : password })
19+ token = response .json ()['token' ]
20+
21+ headers = {
22+ 'Authorization' : "JWT {}" .format (token ),
23+ 'Content-Type' : "application/json" ,
24+ }
25+
26+ api_name = input ("API key's name: " )
27+
28+ response = requests .post (
29+ keys_endpoint ,
30+ headers = headers ,
31+ json = {'name' : api_name })
32+
33+ if response .status_code == 201 :
34+ print ("\n Account API key:" , response .json ()['key' ])
35+ print ("\n Please record this key, it will not be shown again." )
36+
37+ else :
38+ print ('\n [%s]\n %s' % (response .status_code , response .text ))
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """
3+ Create an API key for your account
4+ """
5+ import getpass
6+ import requests
7+ from urllib .parse import urljoin
8+
9+ username = input ("Username: " )
10+ password = getpass .getpass ()
11+
12+ api_base_url = "https://api.probely.com"
13+ auth_endpoint = urljoin (api_base_url , "auth-obtain/" )
14+ keys_endpoint = urljoin (api_base_url , "keys/" )
15+
16+ # Get login token
17+ response = requests .post (auth_endpoint ,
18+ data = {'username' : username , 'password' : password })
19+ token = response .json ()['token' ]
20+
21+ headers = {
22+ 'Authorization' : "JWT {}" .format (token ),
23+ 'Content-Type' : "application/json" ,
24+ }
25+
26+ api_name = input ("API key's name: " )
27+
28+ response = requests .post (
29+ keys_endpoint ,
30+ headers = headers ,
31+ json = {'name' : api_name })
32+
33+ if response .status_code == 201 :
34+ print ("\n Account API key:" , response .json ()['key' ])
35+ print ("\n Please record this key, it will not be shown again." )
36+
37+ else :
38+ print ('\n [%s]\n %s' % (response .status_code , response .text ))
You can’t perform that action at this time.
0 commit comments