Welcome to the Rice Nutrition API documentation. This guide will help you get started with using our API to access rice nutrition data.
An app provides the Client ID and Client Secret needed to request an access token by implementing any of the authorization flows. To create an app, go to your dashboard, click on the Create an app button and enter the following information:
The access token is a string which contains the credentials and permissions that can be used to access a given resource (e.g ricenutrition, ricevarieties).
In order to request the access token you need to get your Client_ID and Client Secret:
The Client ID can be found here. The Client Secret can be found behind the View client secret link.
With our credentials in hand, we are ready to request an access token. This tutorial uses the Client Credentials, so we must:
curl -X POST "https://sso-nutri.ricethailand.go.th/realms/myrealm/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"
The response will return an access token valid for 1 hour:
{
"access_token": "BQDBKJ5eo5jxbtpWjVOj7ryS84khybFpP_lTqzV7uV-T_m0cTfwvdn5BnBSKPxKgEb11",
"token_type": "Bearer",
"expires_in": 3600
}
For this example, we will use the Get Rice variety endpoint to request information about an rice variety. According to the API Reference, the endpoint needs the ID of the variety.
curl "http://localhost:3000/api/rice/nutrition/672492543a7a7a8a0fb4a08d" \
-H "Authorization: Bearer BQDBKJ5eo5jxbtpWjVOj7ryS84khybFpP_lTqzV7uV-T_m0cTfwvdn5BnBSKPxKgEb11"
if everything goes well, the API will return the following JSON response:
{
"riceVarieties": {
"th": "เขียวใหญ่",
"en": "Khiao Yai"
},
"cropSampleID": 3,
"variety": "6723afa27afca63cb95c5731",
"cropSampleName": "เขียวใหญ่",
"dataSource": "การประชุมวิชาการข้าวและธัญพืชเมืองหนาว ครั้งที่ 34 พ.ศ.2560",
"nutritionData": [],
"href": "http://localhost:3000/api/rice/nutrition/672492543a7a7a8a0fb4a08d",
"id": "672492543a7a7a8a0fb4a08d"
}