Request an access token
To access the API, you must request an access token first. To request an access token, make a POST call to the Auth0 token URL. You will receive your client_id
and client_secret
from the DevMatch team.
curl --request POST \
--url 'https://devmatch.us.auth0.com/oauth/token' \
--header 'content-type: application/json' \
--data grant_type=client_credentials \
--data client_id=YOUR_CLIENT_ID \
--data client_secret=YOUR_CLIENT_SECRET \
--data audience=api.devmatch.io
You receive an HTTP 200
response with a payload containing access_token
, token_type
, and expires_in
values:
{
"access_token":"eyJz93a...k4laUWw",
"token_type":"Bearer",
"expires_in":86400
}
Use the token to call an API
Access tokens are used in token-based authentication to allow an application to access the API. Once an application has received an access token, it will include that token as a credential when making API requests. To do so, it should transmit the access token to the API as a Bearer credential in an HTTP Authorization header.
Use the token you just requested to call the Get Problems API.
curl --location 'https://94s1zv81nb.execute-api.us-west-2.amazonaws.com/api/problems' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJS...'
You will receive a list of problems:
[
{
"id": 1,
"title": "Puppy save and rescue",
"description": "Problem description",
"time_limit": 100,
"skills": "python",
"public": 1,
"owner_id": "createProbAuthor-001",
"difficulty": "easy",
"date_created": "2023-07-19 18:15:38",
"open": 0,
"like_count": 1,
"open_count": 0,
"view_count": 2,
"opened": false,
"solved": false,
"open_events": [],
"submissions": [],
"_public": true,
"is_current_user_admin": false,
"liked_by_current_user": false,
"viewed_by_current_user": false
}
]
If you do get this list, then you have successfully called the API.