Fuel Site Monitor - Reference

This sections contains:

AWS4 signing protocol

This section provides details about signing the request with AccessKey and SecretKey using AWS4 signing protocol.

Using Postman

Create a request in Postman with the following configurations,

Auth type AWS Signature
Access key AccessKey provided to merchant
Secret key SecretKey provided to merchant

Java

// Create a request

Request<Void> request = new DefaultRequest<Void>("execute-api");
request.setEndpoint(URI.create("https://{baseurl}"));
request.setHttpMethod(HttpMethodName.GET);
request.setResourcePath("/site-status");
request.addHeader("Content-Type", "application/json");
request.addHeader("x-api-key", "{API_Key}");

// Define the AWS credentials

BasicAWSCredentials awsCredentials = new BasicAWSCredentials("{AccessKey}", "{SecretKey}")

// Sign the request with AWS4 signing protocol

AWS4Signer signer = new AWS4Signer();
signer.setRegionName(Region.getRegion(Regions.fromName("us-east-1")).getName());
signer.setServiceName("execute-api");
signer.sign(request, awsCredentials);

// Send the request

Response<String> response = new AmazonHttpClient(new ClientConfiguration())
  .requestExecutionBuilder()
  .executionContext(new ExecutionContext(true))
  .request(request)
  .errorResponseHandler(new ErrorResponseHandler())
  .execute(new SuccessResponseHandler());

NodeJS

var AWS = require('aws-sdk');
var rp = require('request-promise')
var aws4 = require('aws4')

var credentials = {
  accessKeyId: '{AccessKey}',
  secretAccessKey: '{SecretKey}'
}

var opts = {
  host: '{baseurl}',
  method: ‘GET’
  path: '/site-status',
  uri: ' https://{baseurl}/site-status',
  json: true,
  headers: {
      'x-api-key': '{API_Key}'
  }
}

opts.region = 'us-east-1'
opts.service = 'execute-api'

var signer = new aws4.RequestSigner(opts, credentials)
signer.sign()

rp(opts)
.then( (html)=> console.log(html) )
.catch( (e)=> console.log('failed:' + e) )

Generating timestamps

You must provide startTime in yyyy-MM-dd HH:mm:ss format, where

Variable Description
yyyy 4-digit year
MM 2-digit month in year, for example January is 01.
dd Day in month
HH Hour in day (0-23)
mm Minute in hour
ss Second in minute

This section provides details about generating timestamp in different programming languages.

Java

DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd          
                                                                   HH:mm:ss").withZone(ZoneId.of("UTC"));
String formattedCurrentUTCDateTime = dateTimeFormatter.format(Instant.now());

Javascript

`function getFormattedUTCCurrentDateTime() {
  var currentDate = new Date();
  var formattedDateTime = currentDate.getUTCFullYear() + "-" +
  ("0" + (currentDate.getUTCMonth() + 1)).slice(-2) + "-" +
  ("0" + currentDate.getUTCDate()).slice(-2) + " " +
  ("0" + currentDate.getUTCHours()).slice(-2) + ":" +
  ("0" + currentDate.getUTCMinutes()).slice(-2) + ":" +
  ("0" + currentDate.getUTCSeconds()).slice(-2);
  return formattedDateTime;
}