Example for requesting data from the last complete interval using cURL
To request data from the last complete interval
In the following procedure, replace the following variables with the appropriate values:
Variable | Description |
|---|---|
HOST | CRA host name |
PORT | CRA port number |
SERVICE_NAME | Service name for the Host Server that you want to connect to |
BEARER_TOKEN | Token that you receive after performing the login request |
SESSION_ID | Session ID that you receive after the getData request |
Log in by using the following commands:
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/<SERVICE_NAME>/login' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"username": "<USERID>",
"password": "<PASSWORD>"
}'Request data for a specific view by using the following commands. Keep the session for this view open by specifying close=N in the request parameter. The request returns the session ID created for this call.
For each call that uses close=N without a session ID, CRA creates new session. The new session doesn't close until the token is invoked or a request to close the session is triggered.
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/getData?product=<PRODUCT_NAME>&select=<VIEW_NAME>&period=%3D&close=N' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-d ''Request data from the open session for the last complete interval by using the following commands. From the request response, copy the session value into <SESSION_ID>.
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/getData?product=<PRODUCT_NAME>&select=<VIEW_NAME>&period=%2A%20%2A%20PREV&close=N' \
-H 'accept: application/json' \
-H 'session: <SESSION_ID>' \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-d ''By default, the session token is valid for 15 minutes. To continue using the session, if the request rate is longer (for example, if the view interval is longer), you must keep the session alive. To do so, use the following commands, and from the request response, copy the session value into <SESSION_ID>.
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/keepalive' \
-H 'accept: application/json' \
-H 'session: <SESSION_ID>' \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-d ''When you no longer need data, close the session or log off by using one of the following commands. From the request response, copy the session value into <SESSION_ID>.
Close the specific session
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/close' \
-H 'accept: application/json' \
-H 'session: <SESSION_ID>' \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-d ''Log off
curl -X 'POST' \
'http://<HOST>:<PORT>/cra/serviceGateway/services/logoff' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <BEARER_TOKEN>' \
-d ''