Web hooks: General information
Web hooks are configurable inside Nomadia Field Service GeoScheduling to call your public endpoints and inform your server of occurring actions with many configurable events through the circulation module
(on appointments, customers, unavailabilities, events that are transforming on resource calendar : Apply new JobType, workedWeek, DutyPeriod (mostly invoked from Attendance Module)...)
Events triggable on monitoring:
- appointments
- customers
- unavailabilities
- resource calendar : applying new JobType, workedWeek, DutyPeriod (mostly invoked from Attendance Module)
- referents entities : creating , updating, disabling area,worksite,team,type of resource, of unavailabilities, of days... (mostly invoked from actions in admin module)
- optimization events
- web service requests / responses
- application messages (message service between users)
- application starts/stops
Each event can be monitored in real time by an inside-listener from the circulation. It will inject the event in the circulation context.
Then, there are two ways to send that information to your web hook:
- Either through send-entities-processor: REST JSON / REST XML / SOAP WS calls to synch entities changes (mainly appointments, customers and unavailabilities)
towards a dedicated third part web service.
Your web service has to implement a given schema contract (see the setEntityFromProperties request/response in the API).
One can have a look too at the WSDL contract
Nomadia Field Service defines itself a web service implementing this schema : it can be tested with the setEntityFromProperties API test page
- Or through rest-output-medium for any configurable REST web service calls
IMPORTANT NOTE : The requests sent to your web hook are not stored in any case in Nomadia Field Service database.
If it fails to reach your web hook endpoint for any reason (internal error, network error), an error log will be logged on Nomadia Field Service's side, and an application alert log will be stored too.
The administrator of OptiTime will have to subscribe to application alerts for "Export errors" and "Communication errors" to be able to consult those errors in the application alerts of the callcenter.
A single endpoint is needed to synch as many entity kinds as wanted, but for streaming supervision, the solution of one endpoint dedicated to one entity kind should be prefered.
We therefore encourage you to define as many endpoints as necessary to manage your business entities.
How to synch Nomadia Field Service entities with a send-entities-processor
The schema of the circulation send-entities-processor is available in (the circulation documentation)
- <listField> has to contain a list of semicolon separated exchange model fields to be exported
- <entity> can be given to set the entity name to be exported (required if not all the required fields were given previously)
- <requestFormat> the request data format (can be "json" "xml" or "soap")
- <ws-key> the WS key to be authenticated
- <ws-user> the WS user to be authenticated
- <ws-password> the WS password to be authenticated
- <output-medium> the output medium
The output-medium will define an http-connection with the following characteristics:
- <url> the URL of the third part WS endpoint
- <verb> POST method only
- <content-type> "application/json;charset=UTF-8" for "json" or "text/xml;charset=UTF-8" for "xml" and "soap"
How to call your web hooks by configuring a rest-output-medium
The rest-output-medium is designed to be able to call almost any kind of web hook, with either direct authentication or with a first pass connection through a token retrieval (OAuth2).
The token is then available through a "X-auth-token" HTTP header that will be available in subsequent requests.
Its life duration is indifferent to Opti-Time : a new authentication request will be issued as soon as a previous request will have received a 401 Unauthorized error code (HTTP/1.0 - RFC 1945).
After 3 tries of authentication, if the token still can't be retrieved, the web hook request will be abandoned.
The schema of the circulation rest-output-medium is available in (the circulation documentation)
Here are the parameters to configure it
- <url> the URL of the third part web hook endpoint: only fill this parameter if you don't need authentication and intend to send GET or POST requests with "application/x-www-form-urlencoded" content-type.
If not defined, then the connection will have to be defined further in the http-connection element here after
- <verb> the HTTP method on calling URL: only fill this parameter if you don't need authentication and intend to send GET or POST requests with "application/x-www-form-urlencoded" content-type.
If not defined, then the connection will have to be defined further in the http-connection element here after
- <content-type> the content-type on calling URL: only fill this parameter if you don't need authentication and intend to send GET or POST requests with "application/x-www-form-urlencoded" content-type.
If not defined, then the connection will have to be defined further in the http-connection element here after
- <http-init-connection> the HTTP init connection can be defined if a two steps authentication is required for a token retrieval
- <http-connection> the HTTP connection will be used if no url was given before, and possibly with the token previously retrieved by the http-init-connection
- <resp-analyzer> this specific parameter aims to call an internal response analyzer after the request was emitted, to do post treatment. If your stream requires to analyze a given response, please ask for R&D support
- <query-params> the web hook query parameters to be defined (described here after)
The rest-output-medium can define an http-connection with the following characteristics (BTW: same elements as for the http-init-connection):
- <custom-class-name> may be defined to give a specific HttpConnection inherited class to define the process to retrieve an access token that may be available to an http-output-medium (generally com.geoconcept.schedule.logic.circulation.impl.custom.AuthTokenConnection). The retrieved token is then passed to subsequent requests through the "X-auth-token" header.
- <url> the URL of the third part WS endpoint
- <verb> GET/POST/PUT/PATCH HTTP method
- <user> user to authenticate
- <password> password for user authentication
- <content-type> content-type header (defaults to "application/json;charset=ISO-8859-1")
- <authorization> not used
- <header> other specific headers to set
Build the request parameters with query-params
A set of request parameters can be defined with as many query-params as needed. Each query-param is defined by 3 elements:
- <var-name> the name of the HTTP query parameter to use for your web service beeing able to parse the parameters.
- <var-marshaller> A marshaller name for Opti-Time to fill the HTTP query parameter value (from a given circulation context or not) can be :
- CIRC_MESSAGE: to retrieve the circulation output medium incoming flow
- CIRC_PARAM: to extract a single exchange model field (described in the "var-value" element) out of a given entity found in the circulation context (a listener must have put its referring entity in the circulation context)
- RESOURCE_CIRC_PARAM: to compose a whole message (JSON, XML or any kind) containing placeholders with fields from the exchange model
(the initial message is found in a notifier.properties resource, which name is described in the "var-value" element.
A placeholder is defined with brackets and the pattern [MY_EXCHANGE_MODEL_FIELD]).
The entity from which to extract the placeholder fields has to be found in the circulation context.
- RESOURCE_MESSAGE: to retrieve a given message out of a notifier.properties resource (which name is described in the "var-value" element)
- <var-value> the defaut value of the HTTP query parameter to set
Sample notifier.properties resource to define a JSON request
notifier.properties is a ressource file that can be tuned in the Opti-Time config\param\resources subdirectory.
Remind that every exchange model field between brackets "[]" will be replaced with its subsequent value retrieved in the circulation context:
Here is the documentation of the exchange model out of which placeholders can be used.
One can use some indirections with the fields whose type are ID_FOREIGN or IDS_LIST, to access the linked entity's fields too.
For instance, suppose an appointment was put in the circulation context by an appointment-inside-listener, as an action on the appointment was done anywhere on Opti-Time.
Then one can access its customer's name through a placeholder [CUSTOMER.CUSTOMERNAME] (dotted notation to access fields of linked entities).
For IDS_LIST fields, they refers to a list of foreign entities ID. To export only a single ID, one can give its index between parenthesis: "TASKTYPES(2)" will only export the 3rd ID of the appointment's tasktypes (0 indexed).
Therefore, one can access the 3rd tasktype name of an appointment with "TASKTYPES(2).TASKTYPENAME"
And to retrieve every tasktype names, the notation with parenthesis without any index will do the trick "TASKTYPES().TASKTYPENAME"
An indirection on an IDS_LIST field without any parenthesis like "TASKTYPES.TASKTYPENAME", will only export the first item value, hence, the first tasktype's name only.
notifier.restoutputmedium.appointment.create = {"myJsonAppointmentObject" : {"myappointmentId" : "[APPOINTMENTID]", "mycustomerId" : "[CUSTOMERID]","minimumBeginDate" : "[DATEMINBEGIN]","maximumEndDate" : "[DATEMAXEND]","status" : "confirmed", "myworkers" : "[ASSIGNEDRESOURCES]","beginDate" : "[DATETIME_APPOINTMENT]","endDate" : "[DATETIME_APPOINTMENT_END]"}}
notifier.restoutputmedium.appointment.update = {"myJsonAppointmentObject" : {"myappointmentId" : "[APPOINTMENTID]", "mycustomerId" : "[CUSTOMERID]","minimumBeginDate" : "[DATEMINBEGIN]","maximumEndDate" : "[DATEMAXEND]","status" : "confirmed", "myworkers" : "[ASSIGNEDRESOURCES]","beginDate" : "[DATETIME_APPOINTMENT]","endDate" : "[DATETIME_APPOINTMENT_END]"}}
notifier.restoutputmedium.appointment.delete = {"myJsonAppointmentObject" : {"myappointmentId" : "[APPOINTMENTID]"}}
Sample circulation_config.xml file to call 2 kinds of web hooks on any action on confirmed appointments upon their tasktype
This circulation configuration file can by set in the circulation_config.xml file under Opti-Time config/param directory.
Its name "circulation_config.xml" should be defined in the application_init.xml file under Opti-Time config/param directory.
#### Template Circulation configuration: ####
Confirmed appointments listener calls 2 kinds of WS upon the tasktype of the appointments
app-listener-confirmed
false
confirmed-passage
*:*:0,*:31:1,31:31:0
confirmed-passage
false
COPY
metro-confirmed
other-confirmed
metro-confirmed
false
app-metro-notifier
ML
ERDFAM
other-confirmed
false
app-other-notifier
CT
INS
REP
app-metro-notifier
false
appointmentUpdateMetroMedium
pseudoMarshaller
app-other-notifier
false
appointmentUpdateOtherMedium
pseudoMarshaller
appointmentUpdateMetroMedium
authRequest
appointmentUpdateMetroRequest
RESOURCE_CIRC_PARAM
notifier.restoutputmedium.appointment.update.metro
appointmentUpdateOtherMedium
authRequest
appointmentUpdateOtherRequest
RESOURCE_CIRC_PARAM
notifier.restoutputmedium.appointment.update.other
defaultUnmarshaller
com.geoconcept.schedule.logic.circulation.impl.PseudoUnmarshaller
pseudoMarshaller
com.geoconcept.schedule.logic.circulation.impl.PseudoMarshaller
line-by-line
false
appointmentUpdateMetroRequest
PUT
https://myserver.com:30910/scheduling/appointmentMetro/updated
adminuser
adminpassword
application/json;charset=UTF-8
appointmentUpdateOtherRequest
PUT
https://myserver.com:30910/scheduling/appointmentOther/updated
adminuser
adminpassword
application/json;charset=UTF-8
authRequest
com.geoconcept.schedule.logic.circulation.impl.custom.BasicConnection
GET
https://myserver.com:30910/scheduler/health/ping
application/json;charset=UTF-8