Difference between revisions of "Internal GCAPI"

From GrandCare Systems
Jump to navigation Jump to search
Line 1: Line 1:
To access the Como API you first need the passcodes to the system via [[GCManage API]].
= Calling GCAPI =
A basic call to GCAPI looks like this:
http://[como-URL]/api/[api-subsystem].php?passcode=[my-passcode]&op=[operation]&encoding=[json|xml]


If you're on the same network as the GrandCare system, you can call directly to it's IP address. If not, you'll need to get the public URL from the [[GCManage API]] [[GCManage API#remotelogin|remotelogin]] service.
The como URL and passcode are from the results of a [[GCManage API]] remote login call. The como URL is what GCManage determines is the path to the como system. This can either be proxied or the direct IP of the system. passcode is the authentication mechanism used by GCAPI -- it is a code generated every 24 hours by a system and reported to GCManage. subsystem names the subsystem you want to work on and operation defines the actual operation to perform. Each operation can have a number of other parameters that will be passed via other parameters in the URL.


This URL (whether private IP or public address) will be referenced as '''$SystemAddress''' in the rest of the documentation.
= Local Application Authentication =
Applications may also want to call the API without an associated GCManage account. GrandCare will provide each application an "application key" that allows for a simple way to fetch the required passcodes. To do this, call the API via "localhost" using the following URL:
http://[como-URL]/api/system.php?op=getpasscodes&appkey=[gc-provided-app-key]


'''$SystemAddress Examples'''
This will return the required passcodes for making authenticated calls to the API. See the section on the [[#System API|System API]] Subsystem for more information about the [[#getpasscodes|getpasscodes]] API call.
http://gcmanage.grandcare.com:21000
http://192.168.0.5
http://10.100.1.5


= Services =
= Results From GCAPI =
* Global Parameters
The response from GCAPI will either be encoded in JSON or XML, depending on the requested encoding. By default the response will be encoded in XML.
** '''op''': API Operation (see list below)
** '''encoding''' ("json" or "xml")
** '''passcode''': System passcode from GCManage API.  Note: passcodes are not static.
* Use GET or POST requests
* Returns data with the namespace ''gcapi''
* gcapi->result will be "SUCCESS" or "FAILURE"
** In case of FAILURE, there will also be a key "fail-message" describing the failure. See [[#Failure examples|Examples]]


== History API ==
== XML Results ==
* URL: $SystemAddress/api/history.php
By default, GCAPI responds to commands by returning an XML document. Here is the most basic success result:


=== bp (Blood Pressure) ===
<gcapi>
  $ curl "http://10.100.1.2/api/history.php?op=bp&encoding=json&passcode=YkdrYUpUOEVVRDhMZFQ4SlB6OC9kdz09"
    <result>SUCCESS</result>
</gcapi>
 
The root XML element for all GCAPI results is gcapi. The other always present element is result, which contains either SUCCESS or FAILURE, depending on whether the call succeeded or not. A failure response also contains the fail-message element, which gives the reasons for the failure. For example:
 
<gcapi>
    <result>FAILURE</result>
    <fail-message>Invalid credentials for API call</fail-message>
</gcapi>
 
This result would occur if invalid credentials were supplied during the GCAPI call.
 
== JSON Results ==
GCAPI can also respond by returning a JSON object. Here is the most basic success result:
 
{"gcapi":{"result":"SUCCESS"}}
 
A failure encoded in JSON looks like:
 
{"gcapi":{"result":"FAILURE","fail-message":"Invalid credentials for API call"}}
 
= API Subsystems =
 
== History ==
The History subsystem allows you to fetch ADL and wellness data from a system. All of the operations take the same parameters and return different data.
 
=== bp ===
Fetches blood pressure sensor history from the system
==== Parameters ====
* ''limit'' - [optional] - Limits the number of entries returned. Defaults to 50
* ''offset'' - [optional] - Skip this number of entries. Useful for paging
* ''date'' - [optional] - Returns only entries for this date
* ''days'' - [optional] - Returns entries for the last number of days
* ''devices'' - [optional] - Comma separated list of devices to get data. Can be a single device
* ''resident'' - [optional] - ID of resident to limit data to
==== Results ====
SUCCESS, the total number of readings, and a list readings.
===== xml =====
  <gcapi>
<result>SUCCESS</result>
<bp>
<timestamp>05/12/12 09:35:44</timestamp>
<deviceId>1001</deviceId>
<residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId>
<systolic>138</systolic>
<diastolic>88</diastolic>
<pulse>49</pulse>
<mean-ap>108</mean-ap>
</bp>
<bp>
<timestamp>05/11/12 07:11:08</timestamp>
<deviceId>1001</deviceId>
<residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId>
<systolic>128</systolic>
<diastolic>84</diastolic>
<pulse>58</pulse>
<mean-ap>98</mean-ap>
</bp>
<totalEntries>2</totalEntries>
</gcapi>
===== json =====
  {
  {
     "gcapi": {
     "gcapi": {
Line 53: Line 107:


=== weight ===
=== weight ===
  $ curl "http://10.100.1.2/api/history.php?op=weight&encoding=json&passcode=YkdrYUpUOEVVRDhMZFQ4SlB6OC9kdz09"
Fetches scale history from the system
==== Parameters ====
* ''limit'' - [optional] - Limits the number of entries returned. Defaults to 50
* ''offset'' - [optional] - Skip this number of entries. Useful for paging
* ''date'' - [optional] - Returns only entries for this date
* ''days'' - [optional] - Returns entries for the last number of days
* ''devices'' - [optional] - Comma separated list of devices to get data. Can be a single device
* ''resident'' - [optional] - ID of resident to limit data to
==== Results ====
SUCCESS, the total number of readings, and a list readings.
===== xml =====
  <gcapi>
<result>SUCCESS</result>
<weight>
<timestamp>05/16/12 07:30:26</timestamp>
<deviceId>1000</deviceId>
<residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId>
<value>179.6</value>
</weight>
<weight>
<timestamp>05/15/12 08:00:52</timestamp>
<deviceId>1000</deviceId>
<residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId>
<value>179.8</value>
</weight>
<totalEntries>1354</totalEntries>
</gcapi>
 
===== json =====
  {
  {
     "gcapi": {
     "gcapi": {
Line 75: Line 157:
  }
  }


=== temp (Indoor Temperature) ===
=== temp ===
  $ curl "http://10.100.1.2/api/history.php?op=temp&encoding=json&passcode=YkdrYUpUOEVVRDhMZFQ4SlB6OC9kdz09"
Fetches temperature sensor history from the system
==== Parameters ====
* ''limit'' - [optional] - Limits the number of entries returned. Defaults to 50
* ''offset'' - [optional] - Skip this number of entries. Useful for paging
* ''date'' - [optional] - Returns only entries for this date
* ''days'' - [optional] - Returns entries for the last number of days
* ''devices'' - [optional] - Comma separated list of devices to get data. Can be a single device
==== Results ====
SUCCESS, the total number of readings, and a list readings.
===== xml =====
  <gcapi>
<result>SUCCESS</result>
<temp>
<timestamp>09/14/10 02:50:29</timestamp>
<deviceId>1070</deviceId>
<value>70</value>
</temp>
<temp>
<timestamp>09/14/10 01:37:27</timestamp>
<deviceId>1070</deviceId>
<value>71</value>
</temp>
<totalEntries>2</totalEntries>
 
</gcapi>
 
===== json =====
  {
  {
     "gcapi": {
     "gcapi": {
Line 93: Line 201:
         ],
         ],
         "totalEntries": "2"
         "totalEntries": "2"
    }
}
=== bed ===
Fetches bed sensor history from the system
==== Parameters ====
* ''limit'' - [optional] - Limits the number of entries returned. Defaults to 50
* ''offset'' - [optional] - Skip this number of entries. Useful for paging
* ''date'' - [optional] - Returns only entries for this date
* ''days'' - [optional] - Returns entries for the last number of days
* ''devices'' - [optional] - Comma separated list of devices to get data. Can be a single device
==== Results ====
SUCCESS, the total number of readings, and a list readings.
===== xml =====
<gcapi>
<result>SUCCESS</result>
<totalEntries>1</totalEntries>
<bed>
<timestamp>...</timestamp>
<device-id>...</device-id>
<value>[Occupied|Unoccupied]</value>
</bed>
</gcapi>
===== json =====
{
    "gcapi": {
        "result": "SUCCESS",
        "bed": [{
                "timestamp": "...",
                "device-id": "...",
                "value": "[Occupied|Unoccupied]"
        }],
        "totalEntries": "1"
     }
     }
  }
  }

Revision as of 19:28, 2 August 2012

Calling GCAPI

A basic call to GCAPI looks like this:

http://[como-URL]/api/[api-subsystem].php?passcode=[my-passcode]&op=[operation]&encoding=[json|xml]

The como URL and passcode are from the results of a GCManage API remote login call. The como URL is what GCManage determines is the path to the como system. This can either be proxied or the direct IP of the system. passcode is the authentication mechanism used by GCAPI -- it is a code generated every 24 hours by a system and reported to GCManage. subsystem names the subsystem you want to work on and operation defines the actual operation to perform. Each operation can have a number of other parameters that will be passed via other parameters in the URL.

Local Application Authentication

Applications may also want to call the API without an associated GCManage account. GrandCare will provide each application an "application key" that allows for a simple way to fetch the required passcodes. To do this, call the API via "localhost" using the following URL:

http://[como-URL]/api/system.php?op=getpasscodes&appkey=[gc-provided-app-key]

This will return the required passcodes for making authenticated calls to the API. See the section on the System API Subsystem for more information about the getpasscodes API call.

Results From GCAPI

The response from GCAPI will either be encoded in JSON or XML, depending on the requested encoding. By default the response will be encoded in XML.

XML Results

By default, GCAPI responds to commands by returning an XML document. Here is the most basic success result:

<gcapi>
   <result>SUCCESS</result>
</gcapi>

The root XML element for all GCAPI results is gcapi. The other always present element is result, which contains either SUCCESS or FAILURE, depending on whether the call succeeded or not. A failure response also contains the fail-message element, which gives the reasons for the failure. For example:

<gcapi>
   <result>FAILURE</result>
   <fail-message>Invalid credentials for API call</fail-message>
</gcapi>

This result would occur if invalid credentials were supplied during the GCAPI call.

JSON Results

GCAPI can also respond by returning a JSON object. Here is the most basic success result:

{"gcapi":{"result":"SUCCESS"}}

A failure encoded in JSON looks like:

{"gcapi":{"result":"FAILURE","fail-message":"Invalid credentials for API call"}}

API Subsystems

History

The History subsystem allows you to fetch ADL and wellness data from a system. All of the operations take the same parameters and return different data.

bp

Fetches blood pressure sensor history from the system

Parameters

  • limit - [optional] - Limits the number of entries returned. Defaults to 50
  • offset - [optional] - Skip this number of entries. Useful for paging
  • date - [optional] - Returns only entries for this date
  • days - [optional] - Returns entries for the last number of days
  • devices - [optional] - Comma separated list of devices to get data. Can be a single device
  • resident - [optional] - ID of resident to limit data to

Results

SUCCESS, the total number of readings, and a list readings.

xml
<gcapi>

<result>SUCCESS</result> <bp> <timestamp>05/12/12 09:35:44</timestamp> <deviceId>1001</deviceId> <residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId> <systolic>138</systolic> <diastolic>88</diastolic> <pulse>49</pulse> <mean-ap>108</mean-ap> </bp> <bp> <timestamp>05/11/12 07:11:08</timestamp> <deviceId>1001</deviceId> <residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId> <systolic>128</systolic> <diastolic>84</diastolic> <pulse>58</pulse> <mean-ap>98</mean-ap> </bp> <totalEntries>2</totalEntries>

</gcapi>
json
{
   "gcapi": {
       "result": "SUCCESS",
       "bp": [
           {
               "timestamp": "07/31/12 08:15:57",
               "deviceId": "1001",
               "residentId": "cf6ff892-3124-41ef-8c77-e729f0f66fc5",
               "systolic": "134",
               "diastolic": "95",
               "pulse": "54",
               "mean-ap": "117"
           },
           {
               "timestamp": "07/28/12 07:51:16",
               "deviceId": "1001",
               "residentId": "cf6ff892-3124-41ef-8c77-e729f0f66fc5",
               "systolic": "134",
               "diastolic": "89",
               "pulse": "51",
               "mean-ap": "104"
           }
       ],
       "totalEntries": "2"
   }
}

weight

Fetches scale history from the system

Parameters

  • limit - [optional] - Limits the number of entries returned. Defaults to 50
  • offset - [optional] - Skip this number of entries. Useful for paging
  • date - [optional] - Returns only entries for this date
  • days - [optional] - Returns entries for the last number of days
  • devices - [optional] - Comma separated list of devices to get data. Can be a single device
  • resident - [optional] - ID of resident to limit data to

Results

SUCCESS, the total number of readings, and a list readings.

xml
<gcapi>

<result>SUCCESS</result> <weight> <timestamp>05/16/12 07:30:26</timestamp> <deviceId>1000</deviceId> <residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId> <value>179.6</value> </weight> <weight> <timestamp>05/15/12 08:00:52</timestamp> <deviceId>1000</deviceId> <residentId>cf6ff892-3124-41ef-8c77-e729f0f66fc5</residentId> <value>179.8</value> </weight> <totalEntries>1354</totalEntries>

</gcapi>
json
{
   "gcapi": {
       "result": "SUCCESS",
       "weight": [
           {
               "timestamp": "07/31/12 08:14:45",
               "deviceId": "1000",
               "residentId": "cf6ff892-3124-41ef-8c77-e729f0f66fc5",
               "value": "176.6"
           },
           {
               "timestamp": "07/28/12 07:49:32",
               "deviceId": "1000",
               "residentId": "cf6ff892-3124-41ef-8c77-e729f0f66fc5",
               "value": "176.2"
           }
       ],
       "totalEntries": "2"
   }
}

temp

Fetches temperature sensor history from the system

Parameters

  • limit - [optional] - Limits the number of entries returned. Defaults to 50
  • offset - [optional] - Skip this number of entries. Useful for paging
  • date - [optional] - Returns only entries for this date
  • days - [optional] - Returns entries for the last number of days
  • devices - [optional] - Comma separated list of devices to get data. Can be a single device

Results

SUCCESS, the total number of readings, and a list readings.

xml
<gcapi>

<result>SUCCESS</result> <temp> <timestamp>09/14/10 02:50:29</timestamp> <deviceId>1070</deviceId> <value>70</value> </temp> <temp> <timestamp>09/14/10 01:37:27</timestamp> <deviceId>1070</deviceId> <value>71</value> </temp> <totalEntries>2</totalEntries>

</gcapi>
json
{
   "gcapi": {
       "result": "SUCCESS",
       "temp": [
           {
               "timestamp": "07/20/12 12:06:18",
               "deviceId": "103",
               "value": "73"
           },
           {
               "timestamp": "07/20/12 11:53:14",
               "deviceId": "103",
               "value": "74"
           }
       ],
       "totalEntries": "2"
   }
}

bed

Fetches bed sensor history from the system

Parameters

  • limit - [optional] - Limits the number of entries returned. Defaults to 50
  • offset - [optional] - Skip this number of entries. Useful for paging
  • date - [optional] - Returns only entries for this date
  • days - [optional] - Returns entries for the last number of days
  • devices - [optional] - Comma separated list of devices to get data. Can be a single device

Results

SUCCESS, the total number of readings, and a list readings.

xml
<gcapi>

<result>SUCCESS</result> <totalEntries>1</totalEntries>

	<bed>

<timestamp>...</timestamp> <device-id>...</device-id> <value>[Occupied|Unoccupied]</value>

	</bed>
</gcapi>
json
{
   "gcapi": {
       "result": "SUCCESS",
       "bed": [{
               "timestamp": "...",
               "device-id": "...",
               "value": "[Occupied|Unoccupied]"
       }],
       "totalEntries": "1"
   }
}

Assign API

  • URL: $SystemAddress/api/assign.php

Caregiver API

  • URL: $SystemAddress/api/caregiver.php

Care note API

  • URL: $SystemAddress/api/carenote.php

Configure API

  • URL: $SystemAddress/api/configure.php

Device API

  • URL: $SystemAddress/api/device.php

Log API

  • URL: $SystemAddress/api/log.php

Media API

  • URL: $SystemAddress/api/media.php

Medication API

  • URL: $SystemAddress/api/medication.php

Message API

  • URL: $SystemAddress/api/message.php

PIN API

  • URL: $SystemAddress/api/pin.php

Resident API

  • URL: $SystemAddress/api/resident.php

Rule API

  • URL: $SystemAddress/api/rule.php

System API

  • URL: $SystemAddress/api/system.php

Failure examples

Wrong Passcode

{
   "gcapi": {
       "result": "FAILURE",
       "fail-message": "Invalid credentials for API call"
   }
}
Invalid Operation

{
   "gcapi": {
       "result": "FAILURE",
       "fail-message": "Invalid operation for API call"
   }
}
Missing Required Parameter

{
   "gcapi": {
       "result": "FAILURE",
       "fail-message": "Missing required parameter 'logfile'"
   }
}

Other Resources