When a REST interface is called by CIP_CallRESTInterface, its optional call parameters are exposed as Argument_1 through Argument_10. Argument_Count contains the number of supplied arguments.
Execution order: OnBeforeExecute, request URI formula, request body formula, HTTP execution, OnResponse, optional database processing, then OnAfterExecute. If HTTP execution raises an exception, OnError runs and the remaining response and after-execute steps are skipped.
Parser lifetime: A REST interface keeps one MathParser instance across its events and executions. Variables set by an earlier event or call can therefore remain visible even when they are not declared for the current formula. Only the arguments explicitly documented for an event should be treated as guaranteed.
OnBeforeExecute runs after the caller's arguments have been copied into the parser, but before the REST components are configured and before the resource URI and request body formulas run. It has no event-specific declared arguments. Arguments supplied through CIP_CallRESTInterface are normally present, but formulas started with the editor's argument-free test path receive NULL values for Argument_0 through Argument_10.
Result: Although the formula metadata ends with NeedResult=True, the calculated value is ignored and cannot cancel or modify the request. A formula error stops execution before the request is prepared and does not invoke OnError.
Example: Record when request processing started.
CIP_SetRuntimeVariable("RESTStarted", Now());OnGetRequestResourceURI runs while the request is prepared, before it is sent. Its Result becomes the request resource URI. Argument_OriginalRequestResourceURI contains the configured static URI. An empty or NULL-like result produces an empty resource URI. A formula error stops request preparation; it is not handled by OnError.
Example: Keep the configured URI when no dynamic replacement is required.
Result := Argument_OriginalRequestResourceURI;OnGetRequestBody runs while the request is prepared, after the resource URI has been calculated and before the request is sent. Its Result becomes the request body. Argument_OriginalRequestBody contains the configured static body. If the result is empty after trimming, no body is added. A formula error stops request preparation; it is not handled by OnError.
Example: Send the configured body unchanged.
Result := Argument_OriginalRequestBody;OnResponse runs after RESTRequest.Execute completes successfully and before the optional response-to-database processing. It receives Argument_ResponseHEAD, Argument_ResponseContent, Argument_ResponseJSON, Argument_StatusCode and Argument_StatusText. Argument_ResponseJSON is NULL when the response is not JSON.
Result: Although the formula metadata says NeedResult=True, the value is ignored. A formula error propagates and prevents both database processing and OnAfterExecute. The five response variables are refreshed only when a valid OnResponse formula exists; otherwise older values can remain in the persistent parser and must not be used by other events.
Example: Preserve the most recent HTTP status for later inspection.
CIP_SetRuntimeVariable("LastRESTStatus", Argument_StatusCode);OnAfterExecute runs after successful HTTP execution and after the response-to-database processing attempt. An error in database processing is displayed but does not prevent this event. An exception from HTTP execution runs OnError and exits before this event, and an OnResponse formula error also prevents it.
Arguments and Result: It has no event-specific declared arguments. Although its metadata says NeedResult=True, the value is ignored. Do not rely on response or caller variables merely because they remain in the persistent parser.
Example: Record completion as a side effect.
CIP_SetRuntimeVariable("RESTFinished", Now());OnError runs only when RESTRequest.Execute raises an exception. Its Result is ignored and Argument_ErrorMessage contains the exception message. It does not handle errors from request preparation, the URI/body formulas, response processing, database import or OnAfterExecute.
Example: Preserve the transport error for later inspection.
CIP_SetRuntimeVariable("LastRESTError", Argument_ErrorMessage);OnHTTPProtocolError runs from the HTTP protocol-error callback when a response object is available. Its Result is ignored. Argument_StatusCode and Argument_StatusText contain the response HTTP status. The formula does not itself decide whether protocol-error processing continues.
Example: Preserve the protocol status code.
CIP_SetRuntimeVariable("LastRESTProtocolStatus", Argument_StatusCode);