How to Access API Gateway - GeorgiaTech-DDI/makerspace_iot GitHub Wiki

How to Use API Gateway 🌁

There are two main ways to utilize the API. They are calling the API by a specific assetID, or calling the API and sorting by a range of dates you would like to grab. Both function calls also allow for the use of a limit function call, allowing you to cap the number of items returned.

Get by AssetID

Parameters:

  • limit: the number of items returned in the json
  • asset: the asset of the tool you are looking to get the information from

A simple call to the API using get by AssetID would look like the following:

https://tfoqg3fqx0.execute-api.us-east-1.amazonaws.com/dev/getByAssetID?asset=Metal_Room_Horizontal_Band_Saw_1&limit=10

The beginning part of the call (tfoqg...) will change every time the api gets deployed, so contact the IoT team, or whoever has access to the API to make sure you have the most updated endpoint link. Aside from that, simply make sure you are using /getByAssetID, followed by the ? character, and setting the desired parameters accordingly. Ensure that when separating parameters in the API call, you seperate them with the '&' character.

April 2024 Note: At the time of writing this we only have one machine's data in the table, and the asset ID is Metal_Room_Horizontal_Band_Saw_1. Consult the dynamoDB table to naming conventions of other machines once they get implemented.

Get by Date

Parameters:

  • asset: name of asset you want to look at
  • date_max: maximum date you want to search for
  • date_min: minimum date you want to search through
  • limit: maximum number of responses in json Note: Ensure the date_max is greater than date_min, otherwise the API call will not work.

A sample call to the API will look like the following:

https://tfoqg3fqx0.execute-api.us-east-1.amazonaws.com/dev/getByDate?date_max=2024-05-01&date_min=2022-01-01&asset=Metal_Room_Horizontal_Band_Saw_1&limit=5

Ensure that after the endpoint you use use /getByDate?, followed by the desired parameters. The proper format for the dates are 'YYYY-MM-DD'. The API call will support you a call that does not include asset, so you can simply search for all data points within a certain date range. Simply, do not include &assett=... in your call. Similarly, it is optional to include the limit parameter. However, make sure at the absolute minimum you are including a date_min, and a date_max parameter, otherwise an error will return.

A sample response to a proper call to the API should look like the following:

Get Current Machine Status

If you want to know if the machine is on or off, add '/status' to the end of the API call. It will return a single json with the key 'status', whose value will be 'on' or 'off'. A sample call is: https://tfoqg3fqx0.execute-api.us-east-1.amazonaws.com/dev/status. A sample response image is below:

This will return {'status':'on'}, when a value contains a time stamp that is greater (more recent) than one minute ago. If no data point exists with a time_stamp greater than one minute, it will say the machine is off.