Get a server access token
To use Shakr API, you need to retrieve an access token using OAuth 2.0. Getting the token is simple with the Client ID and the Client Secret, which were issued to you upon joining Shakr.
An access token is comprised of a server access token and a scoped access token. When you call the API on your server application, a server access token, which has all the privileges, is used. You have to be careful not to expose server access token to the client (such as user's browser) because it has privileges on all the resources made through the API.
To learn more about access tokens, please refer to Authentication and Access Token.
Get server access token
You can issue a server access token using the sample code below. Choose a language of your choice, then fill in your Client ID and Client Secret to request a token.
- cURL
- Node.js
- Elixir
curl 'https://api.shakr.com/oauth/token' \
-X POST \
--header 'Content-Type: application/json' \
--data-raw '{
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET"
}'
{
"access_token": "eyJ0eXA...K-tsNKOcw", // server access token
"created_at": 1611559222,
"token_type": "bearer"
}
const fetch = require('node-fetch');
fetch(
'https://api.shakr.com/oauth/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
grant_type: 'client_credentials',
client_id: 'YOUR_CLIENT_ID',
client_secret: 'YOUR_CLIENT_SECRET',
})
}
)
.then(res => res.json())
.then(({ access_token }) => {
console.log(access_token); // server access token
});
request = %HTTPoison.Request{
url: "https://api.shakr.com/oauth/token",
method: :post,
headers: [
{"Content-Type", "application/json"}
],
body: Jason.encode!(%{
grant_type: "client_credentials",
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET"
})
}
with {:ok, %{status_code: 200} = response} <- HTTPoison.request(request),
{:ok, decoded_json} <- Jason.decode(response.body) do
# server access token
IO.puts(decoded_json["access_token"])
end
access_token
inside the JSON object refers to the server access token. You can save this and use it to make an API call.
After you acquire the server access token, now it's time to choose a template! Let's move on to Choose a creative template.