An application to calculate the logtime of month
Using the 42 API tool, we are going to to make some GET request with curl and receive a JSON data.
To use 42 API we need to create an application then use our u-id and s-id. Here is the getting started documentation.
- Connect to your 42 profile then go the API settings page here.
- Create your new application
Register a new app
. - Now you have UID and a secret ID
Now that you have your UID and secret ID we can try curl command to get the access token.
curl -X POST --data "grant_type=client_credentials&client_id=MY_AWESOME_UID&client_secret=MY_AWESOME_SECRET" https://api.intra.42.fr/oauth/token
You have to chang MY_AWESOME_UID
by your UID and MY_AWESOME_SECRET
by your secret ID.
And voila you got your access_token !
Your first request can be asking more info about your access_token.
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.intra.42.fr/oauth/token/info
You have to change YOUR_ACCESS_TOKEN
by your access_token.
You have the expire time of your token in seconds.
You can ask for the locations and logtime info of a chosen user with his login. Here is the user location data
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" "https://api.intra.42.fr/v2/users/atchougo/locations_stats"
You can add begin_at
and end_at
params to specify data.
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" "https://api.intra.42.fr/v2/users/atchougo/locations_stats?begin_at=2023-11-01&end_at=2023-11-30"
You have to change YOUR_ACCESS_TOKEN
by your access_token.