Authenticate to the UltraDNS REST API by sending your UltraDNS username and password to the authorization endpoint. A successful request returns an access token, which you include in subsequent API requests.
Authentication requires Content-Type: application/x-www-form-urlencoded. Although most UltraDNS API requests use application/json, the login request uses form-encoded data.
Before You Begin
- Have your UltraDNS username and password available.
- Choose one of the HTTP, cURL, or Python examples below. You do not need to run all three.
- Replace
yourusernameandyourpasswordwith your UltraDNS credentials. - For the Python example, use an environment with Python and the
requestslibrary installed.
HTTP Request Example
Send this POST request over HTTPS. The blank line separates the request headers from the form-encoded body.
POST /authorization/token HTTP/1.1
Host: api.ultradns.com
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=yourusername&password=yourpassword
When constructing the request body yourself, URL-encode the username and password values. The cURL and Python examples below perform form encoding for you.
cURL Example
Run this example in a shell that supports backslash line continuation. Each --data-urlencode option encodes a form field.
curl --location 'https://api.ultradns.com/authorization/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=password' \ --data-urlencode 'username=yourusername' \ --data-urlencode 'password=yourpassword'
Python Example
Pass the credentials as a dictionary through the data argument. The requests library form-encodes the values.
import requests
url = "https://api.ultradns.com/authorization/token"
payload = {
"grant_type": "password",
"username": "yourusername",
"password": "yourpassword",
}
headers = {
"Content-Type": "application/x-www-form-urlencoded",
}
response = requests.post(url, headers=headers, data=payload)
print(response.status_code)
print(response.text)
Confirm Successful Authentication
A successful request returns HTTP status 200 OK and a JSON response containing:
-
access_token: The token used to authorize subsequent API requests. -
token_type: The token type,Bearer. -
expires_in: The access token lifetime in seconds. A value of3600means one hour. -
refresh_token: A token used to request a new access token without sending your username and password again.
Use the Access Token
Copy the returned access_token value and include it in the Authorization header of subsequent API requests:
Authorization: Bearer your_access_token
Replace your_access_token with the returned token. Reuse the access token until it expires. After expiration, use the refresh token to obtain a new access token or authenticate again with your username and password.