Web API for GrandNode gives an access to business data stored in GrandNode database. It is OpenAPI.
Note: User should be familiar with GrandNode database structure.
You are also able to use API with Scalar. You need to enable it in the App_Data/appsettings.json file and then you will be able to go to
http://yourstore.com/scalar/v1 and use the browser extension.
1. How to configure WebAPI in GrandNode
2. How to add API user in GrandNode
3. How to generate Web API Token
4. List of available methods
First of all we need to enable API in appsettings.json file. You will find it in App_Data directory in main directory of GrandNode. Edit appsettings.json file.
"FeatureManagement": {
"Grand.Module.Installer": true, "Grand.Module.Migration": true, "Grand.Module.ScheduledTasks": true, "Grand.Module.Api": true }, "BackendAPI": { "Enabled": true, "SecretKey": "your private secret key to use api", "ValidateIssuer": false, "ValidIssuer": "", "ValidateAudience": false, "ValidAudience": "", "ValidateLifetime": true, "ValidateIssuerSigningKey": true, "ExpiryInMinutes": 1440, //generate system model "SystemModel": true },
Enabled - True/False. Specify whether API is enabled or not.
SecretKey - Enter your secret key.
ValidateIssuer - True/False.
ValidIssuer - Specify the provider of the token.
ValidateAudience - True/False.
ValidAudience - Specify the audience. It's client, i.e the receiving party.
ValidateLifetime - True/False.
ValidateIssuerSigningKey - True/False.
ExpiryInMinutes - Specify the expiration time of token.
SystemModel - True/False.
Please note that you need to restart application after each change in appsettings.json file.
In admin panel you will find new tab - Manage API users. Go to Admin panel -> System -> Manage API Users. Then you will see a list of API users. By default list is empty. To add new user, press the "Add new record" button.
In the Email field you need to provide an existing, registered customer in GrandNode. In the next field you need to enter API user password. Please note that it's not account password, it's new password used only in API. You need to remember that you are not able to view this password after save. Number of asterisks is fixed, you will always see 4 of them, it's not related with the length of password. In the last checkbox you can specify if it's active or not.
To show you how to generate Web API Token I will use a Postman in free plan. Open it and create new request.
After save you will see a new window. We need to modify some things in it.
We need to change the request type from GET to POST.
Then you need to provide a request URL - it will be http://yourstore.com/api/token/create.
In the Auth tab, set Auth type to No Auth.
In the next tab we need to add new Header.
In the Key field enter the Content-Type, in Value field enter the application/json, description is empty.
Last step is to provide our API user credentials. Go to Body tab, select "Raw" type and enter the API user email and password.
Please note that password has to be Base64 encoded. You can use this tool to encode password: http://www.utilities-online.info/base64/#.XDNUAVxKi70
{
"email":"admin@yourstore.com",
"password":"MTIzNDU2"
}
And that's all. Just press the "Send" button and if do everything correctly you will see generated token, as it's shown below:
It's a token which you will use to Authenticate your POST requests.
You may list all methods used for any object, by typing “openapi” in your store (http://StoreURL/openapi/v1.json).