...
Table of Contents | ||||||||
---|---|---|---|---|---|---|---|---|
|
...
Where to access
The API gateway api calls and documentation can be accessed one of two ways; the API Gateway web page, or the preconfigured collection from the Postman collection below. The preconfigured collection contains configurations and examples for Authorization and common SharpenDB2 requests.
API Gateway documentation: IZ0 Sharpen Public API, IZ1 Sharpen Public API
Postman download: Postman download
...
View file | ||
---|---|---|
|
Importing Collection into Postman
Download Postman here
Install Postman
Using Postman, import the API collection above
Setting up authorization
In order to send API calls using the API gateway, a system of BearerAuth, apiKey, and apiSecret are used. The steps below will guide you through obtaining the apiKey and apiSecret which will be necessary. Please keep in mind that the user you’re authenticating with will be the user executing the API calls. It is highly recommended you create an automation user within Sharpen which can persist through employee turnover.
Configure the {{base_url}}
Sharpen has two main isolation zones. Depending on which isolation zone you’re interfacing with, the api base url will be different. The Postman collection has a {{base_url}} variable which needs to be set to the appropriate environment before getting started. Once set, this base_url will be used . To start off, you need to gather your Json Web Tokenin any subsequent API call.
Panel | ||
---|---|---|
| ||
By default, the base_url is set to https://api.iz1.sharpen.cx/v1. Please adjust this configuration if you’re using IZ0. |
Navigate to the ‘API Gateway Setup’ folder in Postman from your recently imported collection.
Choose the ‘Variables’ tab.
Check the box next to the appropriate "base_url" variable to correspond with the isolation zone in use.
Only 1 may be checked.
If you login to app.sharpencx.com, then use https://api.sharpen.cx/v1 as your base url.
If you login to app.iz1.sharpen.cx, then use https://api.iz1.sharpen.cx/v1 as your base url.
Click “Save” at the top right.
Gathering your JWT(Json Web Token)
Create Authorization API call method
Using Postman, import the API collection above
Once imported, navigate Navigate to the ‘Create New Authentication’ API call under the ‘Authorization setup' folder
Identify the ‘Authorization’ tab once selecting the api from the folder list
Choose ‘Basic Auth’ from the drop down
Enter the credentials of the Sharpen account corresponding with the account you’re interfacing with
Click ‘Send’
Response should look like
Login to App method (alternative to the method above)
Expand | ||
---|---|---|
| ||
|
Gathering apiKey and apiSecret
Navigate to the ‘Create API Key’ api call under the ‘Authorization Setup’ folder within the imported Postman collection.
Click the ‘Authorization’ tab and choose make sure ‘Bearer Token’ is chosen.
Insert the token gathered in step 7 6 of “Gathering your JWT” here
Navigate to the ‘Body’ tab
If you want an expiration on the token, update the date/time to the proper expiration time. If you do not want an expiration, modify the body to look like this.
Click ‘Send’
The return should look like this
Panel | |
---|---|
| |
| |
The language of the response needs translation to what is expected later in the flow clientId = api-key |
Panel | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
You’re now setup with the API Gateway |
Executing API
...
calls
The examples below are some of many types of API calls which can be run. These show how to create a table, column(s), and query SharpenDB from the API Gateway. Please refer to the core API Gateway referencedocs to see all available API calls.
Create Table
Identify the ‘Create Table’ request under the ‘SharpenDB2’ ‘SharpenDB2->Tables’ folder in the Postman collection
Under the ‘Authorization’ ‘Headers’ tab , set the ‘Type’ to “No Auth”update the
x-api-key
andx-api-secret
values to match that of the values you retrieved in “Gathering apiKey and apiSecret” above.Under the ‘Body’ tab enter your query in JSON format
Code Block language json [ { "name": "TableName" } ]
Click ‘Send’
The request and response should look something like this…
Create Column
Identify the ‘SharpenDB2 Create Column’ request under the ‘SharpenDB2->Columns’ folder in the Postman collection.
Under the ‘Headers’ tab add update the following keys (
x-api-key
andx-api-secret
)Enter the values in correspondence with what was retrieved in the ‘Gathering apiKey and apiSecret’ section of this document values to match that of the values you retrieved in “Gathering apiKey and apiSecret” above.
Under the ‘Body’ tab enter your query in JSON format
Code Block language json [ { "field": "columnName", "type": "varchar(255)", "nullable": true, "default": "string" } ]
Click ‘Send’
The request and response should look something like this…
Query
The Query SharpenDB api allows for your standard SQL operations to be committed to a structured table. This includes SELECT, INSERT, UPDATE, and DELETE.
Identify the ‘SharpenDB2 Select’ request under the ‘SharpenDB2’ ‘SharpenDB2->Queries’ folder in the Postman collection
Under the ‘Authorization’ tab, set the ‘Type’ to “No Auth”Under the ‘Headers’ tab add update the following keys (
x-api-key
andx-api-secret
)Enter the values in correspondence with what was retrieved in the ‘Gathering apiKey and apiSecret’ section of this document values to match that of the values you retrieved in “Gathering apiKey and apiSecret” above.
Under the ‘Body’ tab enter your query in JSON format
Code Block language json { "type": "select", "condition": { "columnName": { "$eq": "value" } } }
Click ‘Send’
The request and response should look something like this…
Anchor | ||||
---|---|---|---|---|
|
The examples below show how to convert common mySQL queries into json bodies for the api requests above.
Expand | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||
SELECT
SELECT with JOIN
INSERT
UPDATE
DELETE
|
Expand | ||||||
---|---|---|---|---|---|---|
| ||||||
|
Code Block |
---|
1<? 2// Set API key/secret pair 3$apiKey = 'aaaa'; 4$apiSecret = 'bbbb'; 5 6// Define the API URL with the desired table name. 7$tableName = 'JSDLookup'; 8$url = "https://api.sharpen.cx/v1/sharpendb/tables/" . $tableName . "/query"; 9 10// Define the query 11$q = '{ 12 "type": "select", 13 "distinct" : false, 14 "limit": 100, 15 "offset": 0, 16 "count": false 17}'; 18 19// Define the api key/secret pair and the content type as json. 20$headers = array( 21 "content-type: application/json", 22 "x-api-key: " . $apiKey, 23 "x-api-secret: " . $apiSecret 24); 25$curl = curl_init(); 26curl_setopt_array($curl, array( 27 CURLOPT_URL => $url, 28 CURLOPT_RETURNTRANSFER => true, 29 CURLOPT_ENCODING => "", 30 CURLOPT_MAXREDIRS => 10, 31 CURLOPT_TIMEOUT => 5, 32 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 33 CURLOPT_CUSTOMREQUEST => "POST", 34 CURLOPT_POSTFIELDS => $q, 35 CURLOPT_HTTPHEADER => $headers, 36)); 37$response = curl_exec($curl); 38curl_close($curl); 39echo $response; |
Query Structure:
The following will result in a SELECT * FROM 'table' query:
Code Block |
---|
1{ 2 'type' => 'select', 3 'distinct' => false, 4 'limit' => 100, 5 'offset' => 0, 6 'count' => false 7} |
Example Response:
This is an example of a full table of data returned via the Query API:
Code Block |
---|
1{ 2 "query": "select * from `JSDLookup` limit 100 offset 0;", 3 "results": [ 4 { 5 "LookupID": 1, 6 "email": "billybob@bob.com", 7 "JSDaccountID": "supersecretID", 8 "username": "1234con1234" 9 }, 10 { 11 "LookupID": 2, 12 "email": "janeydoey@jane.com", 13 "JSDaccountID": "evenmoresecretID", 14 "username": "4567con1234" 15 }, 16 ... 17 ] 18} |
...