HTTP WebHook
Allows gateway to POST
order changes to a registered server.
POST /api/v2/register
Change for HTTP Webhook from V1 to V2 API
Previously, /api/v1/register was a GET method. In /api/v2/register, it is a POST method with the query parameters becoming body parameters.
Register a callback URL to be notified when an active order is modified. This is useful when you have more than one interface modifying orders. The payload in the POST
will be a typical order summary.
Body Parameters
Name | Description | Details |
---|---|---|
http_client | The URL to invoke when an active order is modified. | string, optional |
Example Request
// Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
$.ajax({
url: "http://[TT LAN IP]:8000/api/v1/register",
type: "GET",
data:{
"http_client":"http://10.0.1.18:8989/v1/notify",
},
headers:{
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("HTTP Request Failed");
})
.always(function() {
/* ... */
});
import java.io.IOException;
import org.apache.http.client.fluent.*;
public class SendRequest
{
public static void main(String[] args) {
sendRequest();
}
private static void sendRequest() {
// Register Http Client (GET )
try {
// Create request
Content content = Request.Get("http://[TT LAN IP]:8000/api/v1/register?http_client=http://10.0.1.18:8989/v1/notify")
// Add headers
.addHeader("Authorization", "Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==")
.addHeader("Content-Type", "application/json")
// Fetch request and return content
.execute().returnContent();
// Print content
System.out.println(content);
}
catch (IOException e) { System.out.println(e); }
}
}
// Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
NSURL* URL = [NSURL URLWithString:@"http://[TT LAN IP]:8000/api/v1/register"];
NSDictionary* URLParams = @{
@"http_client": @"http://10.0.1.18:8989/v1/notify",
};
URL = NSURLByAppendingQueryParameters(URL, URLParams);
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"GET";
// Headers
[request addValue:@"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" forHTTPHeaderField:@"Authorization"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Connection
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];
/*
* Utils: Add this section before your class implementation
*/
/**
This creates a new query parameters string from the given NSDictionary. For
example, if the input is @{@"day":@"Tuesday", @"month":@"January"}, the output
string will be @"day=Tuesday&month=January".
@param queryParameters The input dictionary.
@return The created parameters string.
*/
static NSString* NSStringFromQueryParameters(NSDictionary* queryParameters)
{
NSMutableArray* parts = [NSMutableArray array];
[queryParameters enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
NSString *part = [NSString stringWithFormat: @"%@=%@",
[key stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
[value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
];
[parts addObject:part];
}];
return [parts componentsJoinedByString: @"&"];
}
/**
Creates a new URL by adding the given query parameters.
@param URL The input URL.
@param queryParameters The query parameter dictionary to add.
@return A new NSURL.
*/
static NSURL* NSURLByAppendingQueryParameters(NSURL* URL, NSDictionary* queryParameters)
{
NSString* URLString = [NSString stringWithFormat:@"%@?%@",
[URL absoluteString],
NSStringFromQueryParameters(queryParameters),
];
return [NSURL URLWithString:URLString];
}
curl -X "GET" "http://[TT LAN IP]:8000/api/v1/register?http_client=http://10.0.1.18:8989/v1/notify" \
-H "Authorization: Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" \
-H "Content-Type: application/json"
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
try:
r = requests.get(
url="http://[TT LAN IP]:8000/api/v1/register",
params = {
"http_client":"http://10.0.1.18:8989/v1/notify",
},
headers = {
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
)
print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
print('Response HTTP Response Body : {content}'.format(content=r.content))
except requests.exceptions.RequestException as e:
print('HTTP Request failed')
Responses
200 OK (Client successfully registered.)
A client is successfully registered if the gateway can communicate with the server. It does this by making a HEAD request which all web servers and frameworks MUST support.
{
"status": 200,
"message": "Registered client at: http://10.0.1.18:8989/v1/notify"
}
404 Not Found (Unable to reach HTTP server.)
{
"status": 404,
"message": "Client not responding at [CALLBACK_URL]"
}
Example payload sent to registered listeners
{
"elapsedTime": 9,
"uuid": "147e7ccd-c17f-45b4-b5d4-bf14e9c0e244",
"seq": 196, "created": "2015-05-05T13:40:09",
"orderType": "ON_PREMISE",
"locationName": "22",
"state": "located",
"stateStarted": "2015-05-05T13:40:18",
"type": "ORDER_MODIFIED",
"name": "66"
}
Updated over 7 years ago