2022.2

Table Of Contents
In order to tell the printer driver if an API key is missing or incorrect, the Input task of the process
must be set to return a custom HTTP server response code, which is stored in a variable (in this
example: %{http_response}).
Retrieving the API key from the HTTP headers can be done with a Run Script task. For
example:
// Get Bearer Key from raw header
var rawHeaders = Watch.ExpandString("xmlget('/request[1]/header
[1]/rawheaders[1]',Value,KeepCase,NoTrim)");
var authHeaderPattern = /^Authorization=Bearer (\S+)$/m;
var matchResult = rawHeaders.match(authHeaderPattern);
if (matchResult != null && matchResult.length == 2) {
Watch.SetVariable ('bearer_key', matchResult[1]);
Watch.SetVariable ('key_found', 'yes');
} else {
Watch.SetVariable ('bearer_key', '');
Watch.SetVariable ('key_found', 'no');
}
Watch.log('*'+Watch.GetVariable('bearer_key').length+'*', 2);
A following Text Condition task can check if the API key was found (here: the %{key_found}
variable is equal to yes).
Page 64