Welcome to the third part of our Peakboard Hub API series. To learn the basics, like how to get an API key and access token, see our getting started article.
A common use case for Peakboard Hub is using the Hub for data storage. That’s why the Hub API has endpoints for reading and writing data to a Hub list. We will discuss these endpoints in this article.
Endpoint | Method | Description |
---|---|---|
/v1/lists |
GET |
Return a list of all lists in the Hub. |
/v1/lists/list |
GET |
Return a Hub list. |
/v1/lists/list |
POST |
Return Hub list data by using a SQL statement. |
/v1/lists/items |
POST |
Add a new record to a Hub list. |
/v1/lists/items |
PUT |
Change the data of a record in a Hub list. |
/v1/lists/items |
DELETE |
Delete a record from a Hub list. |
In this article, we will use the StockInfo
list as an example.
The correct URL prefix (origin) depends on the version of Peakboard Hub that you’re using. This is the correct prefix for Peakboard Hub Online:
You can also try out the different endpoints in the Swagger portal.
List all lists with GET /v1/lists
This endpoint returns a list of all available lists that are within the scope of the current API key context. Here is an example response:
Get the data with GET /lists/list
Using GET /lists/list
is the easiest way to access the contents of a list. Here are the query parameters:
Parameter | Description |
---|---|
Name |
The name of the list. |
SortColumn |
The name of the column to use for sorting. |
SortOrder |
Either Asc for ascending or Desc for descending. |
SkipRows |
Omit a certain number of rows to enable pagination. |
MaxRows |
The maximum number of rows to return. |
Let’s build an example call that uses an HTTP GET
request to get the row with the highest material number:
Here’s the response to that call. It consists of an array of columns, including the metadata under the columns
node. Under the items
node, there’s an array of data rows. It’s a name-value pair array.
SQL access to the data
The same endpoint, /lists/list
, can also be used in a POST
call to submit a SQL statement and let the Peakboard Hub Database do some work for you. This is the perfect way to aggregate the data before it’s returned to you. That way, there’s no need to transfer large batches of data when you only need an aggregated view.
Suppose we want to know the number of locked and unlocked stock records from our example table. Here is the correct SQL:
So, we wrap this SQL statement into a JSON envelope and submit it in the body of a POST
request to the API endpoint:
Here’s the response:
Add new data with POST /v1/lists/items
The /v1/lists/items
endpoint can be used for any sort of data manipulation. A POST
call to this endpoint will create a new record. Here’s an example request body for record creation:
After a successful record creation, the API returns the entire record, including its ID, which identifies the record.
Change data
To change an existing record in a list, we use the same endpoint as for data creation: /v1/lists/items
. However, we use PUT
instead of POST
. The body is slightly different, because we need to provide the ID of the record to be changed. This example shows how to set the Quantity
field to a new value:
If the action is successful, the response body will contain the corresponding state, to confirm:
Delete data
To delete a record, we use an HTTP DELETE
request. In the request body, we provide the name of the list and the ID of the record to be deleted:
The confirmation for the Peakboard server works similarly to the change of data: