At a high level, getting started with the APIs involves the following steps:
- Get Agari API account
- Generate API credentials
- Generate an API access token
- Use the API
We'll walk through each step in detail below.
Get Agari API account
- Ensure you have an active Agari account
Ensure you already have an active Agari account
You won't get very far if you don't already have an active Agari account set up.
Contact us if you don't already have an account.
Generate API Credentials
Once you have your Agari account, log into the Agari product you wish to make API requests against and manually generate a client_id
and client_secret
:
- Log into your Agari product
- Click on your username in the upper right and select Settings
- Click on the Generate API Secret link to generate an API
client_id
andclient_secret
(the link will read Regenerate API Secret if you have already generated an API client ID/secret previously) - Copy both the
client_id
andclient_secret
that are generated and store them somewhere safe
Keep your
client_id
andclient_secret
secureAPI clients can use your
client_id
andclient_secret
to gain access to the APIs as your user. Keep these values somewhere safe and secure. Never share them with anyone.For security purposes, the
client_secret
will not be displayed again, however you may generate a new one whenever needed by following the steps above.
Generate an API Access Token
Once you have generated a client_id
and client_secret
, generate a temporary access token to gain access to the APIs.
Note: replace YOUR_CLIENT_ID
and YOUR_CLIENT_SECRET
in the code below with the values generated in the prior step.
curl --request POST \
--url https://api.agari.com/v1/ep/token \
--header 'accept: application/json' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET'
import requests
url = "https://api.agari.com/v1/ep/token"
payload = "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
headers = {
'accept': "application/json",
'content-type': "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET");
Request request = new Request.Builder()
.url("https://api.agari.com/v1/ep/token")
.post(body)
.addHeader("accept", "application/json")
.addHeader("content-type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
var data = "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET";
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.agari.com/v1/ep/token");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.send(data);
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api.agari.com/v1/ep/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
response = http.request(request)
puts response.read_body
Upon successful execution of your API call, the response returned will resemble the following (though the value of access_token
will be unique to your request):
{
"access_token": "49442be5e8c054437f16dc2407c76ee60afb1a3e5f0163f9e5883f72883a4985",
"token_type": "Bearer",
"expires_in": 14400,
"created_at": 1592848722
}
Make a note of the access_token
value in the response, as you'll pass this value in subsequent API requests to authenticate.
access_token
validityThe
access_token
is valid for 4 hours (14400
seconds). After 4 hours, request a new access token again using the steps above. See Access and Authentication for more on how to work within this constraint.
Learn more about OAuth 2.0
See OAuth 2.0 to learn more.
Use the API
Having generated an access_token
, you can now make API requests by including the access_token
in your API requests.
The way the access_token
is included depends on the programming language you are using to invoke the APIs.
export ACCESS_TOKEN="your access_token goes here"
curl --request GET \
--url https://api.agari.com/v1/ep/users \
--header 'accept: application/json' \
--header "authorization: Bearer $ACCESS_TOKEN"
import requests
access_token = "your access_token goes here"
url = "https://api.agari.com/v1/ep/users"
headers = {
'accept': "application/json",
'authorization': "Bearer " + access_token
}
response = requests.request("GET", url, headers=headers)
print(response.text)
String accessToken = "your access_token goes here";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.agari.com/v1/ep/users")
.get()
.addHeader("accept", "application/json")
.addHeader("authorization", "Bearer " + accessToken)
.build();
Response response = client.newCall(request).execute();
var accessToken = "your access_token goes here";
var data = null;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://api.agari.com/v1/ep/users");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("authorization", "Bearer $ACCESS_TOKEN");
xhr.send(data);
require 'uri'
require 'net/http'
require 'openssl'
access_token = "your access_token goes here"
url = URI("https://api.agari.com/v1/ep/users")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["accept"] = 'application/json'
request["authorization"] = 'Bearer ' + access_token
response = http.request(request)
puts response.read_body
Updated 5 months ago
What's Next
Access and Authentication |