Authorization

The-Datagarden API uses JSON Webtoken as its main authentication mechanism.

Retrieving your Token

You can retrieve your JSON Web token using the credentials you used to register on our website.

# request token
  >>> url = "https://www.the-datagarden.io/user/token/"
  >>> 
  >>> payload = {'email': 'your email', 'password': 'your password'}
  >>> headers = {'Content-Type': 'application/json'}
  >>> 
  >>> response = requests.request("POST", url, headers=headers, data=payload)
  >>> tokens = response.json()
  >>> print(tokens)
			

The response on this request should provide you with the access and refresh token.

{
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcyODU3ODU1OCwiaWF0IjoxNzI4NDA1NzU4LCJqdGkiOiI2NzhiYWM3YjYwOTA0ZjUwYjA3MWFjNTAwMjk1NTgzNSIsInVzZXJfaWQiOiI3ZDhlNDg2OC1jMmU3LTQ0ZGYtYTY0Ny04M2RiZTViYjM2NmEifQ.6FedYNUVuqOFcNyqMv7_2toLBcQIxuCYH3RagFBqgPA",
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzI4NDA2MDU4LCJpYXQiOjE3Mjg0MDU3NTgsImp0aSI6IjA5NzdhNTBmODBmZTRhOTRhY2U2NTU0NDIwMWFkMGIzIiwidXNlcl9pZCI6IjdkOGU0ODY4LWMyZTctNDRkZi1hNjQ3LTgzZGJlNWJiMzY2YSJ9.MMm6FOp2z9FCdpuhhXJFqhSBknDWrtlxoFqJB5CLOGw"
  }
			

The access token can now be used in your request headers to authorize your requests.

# define request header
  >>> access_token = tokens.get("access")
  >>> 
  >>> headers = {'Content-Type': 'application/json'
  >>> 	'Content-Type': 'application/json',
  >>> 	"Authorization": "Bearer " + access_token
  >>> }
			

Using the Refresh token

The access token will expire after 5 minutes. You can easily use the refresh token to get a new access token. The refresh token itself will expire after 2 hours. Requesting the new access token using the refresh token can be done in the following way.


>>> refresh_token = tokens.get("refresh", None)
>>> paylood = {'refresh': refresh_token}
>>> headers = {'Content-Type': 'application/json'}
>>> url = "https://www.the-datagarden.io/user/token/refresh/"
>>>
>>> response = requests.request("POST", url, headers=headers, data=payload)
>>> tokens = response.json()
>>> print(tokens)
		  

This will give the same response as the request token api call and will provide you with both new access and refresh tokens.