Automic Workload Automation

 View Only
Expand all | Collapse all

AE REST API - Using POST executions endpoint with callback URL

  • 1.  AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 07, 2024 07:22 AM
    Edited by Michael A. Lowry Mar 14, 2024 06:38 AM

    Version 21 of the AE REST API added an option to define a callback URL for more efficient monitoring of executed tasks. This capability is described on the documentation page Polling and Callback Requests. This morning I tried out this capability for the first time, using Postman and its mock server function.

    The relevant REST API is POST /{client_id}​/executions. There you can find examples of the JSON request body that should be delivered with the request. Here is the payload I tried.

    {
      "object_name": "EBM.TEST.SCRI"
      "callback": {
        "type": "http",
        "recurring_mode": "once",
        "http": {
          "url": "https://xxxxxx.mock.pstmn.io",
        }
      }
    }

    Unfortunately, I was not able to get it to work. Without the callback section, it works fine. However, as soon as I include the callback section, the REST process returns response code 500. In the log I see the following messages.

    20240307/115401.289 - 5436   U00045105 Log on of 'MYUSER/TEST' ('218971168') successful, client: '1' (Connection='*CP001#00000068').
    20240307/115401.290 - 5436             /ae/api/v1/0001/executions
    20240307/115401.300 - 5436   U00045014 Exception 'java.lang.NullPointerException: "null"' at 'com.automic.rest.exceptions.ExceptionServiceImpl.getValidationErrorDetails():123'.
    

    I observed the same behavior in both v21.0.8 and v24.0.0. Has anyone used this callback capability successfully?

    Update: There were problems with the submitted JSON, and a firewall blocking callback requests. Read the rest of the thread below for details, or just jump to the summary.



  • 2.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 07, 2024 01:23 PM
    Edited by Michael A. Lowry Mar 13, 2024 11:22 AM

    I did some investigation and discovered that the callback feature likely requires installation of additional software.

    Discovering this took a bit of investigation though.

    1. The EH table schema mentions several fields related to callbacks, including EH_Language and EH_HasCallback.
    2. The description of the field just before these two mentions "EVNT.IA.*"
    3. In client 0, there are two objects, EVNT.IA.RULE and EVNT.IA.WEBHOOK. These have OH_Idnr values lower than 100,000 — usually an indication that the objects are part of the initial data.
    4. Based on these objects’ titles/descriptions, they appear to be related to Intelligent Automation.
    5. Attempting to open either of these objects results in an error.
      Runtime error in object 'XEVNT(GET)', line '00038'. DS_INCL: 'FRAGMENT_EVNT_'/XREQ type: 'GET' not found
    6. An old v21 documentation page on WEBHOOK Events essentially confirms that the objects rely on software not installed, explicitly mentioning prerequisites including Analytics and several other packages.

    The requirement to install additional software is not mentioned anywhere in the documentation of the callback feature. If extra software must indeed be installed before the callback feature will work as advertised, this should be clearly stated in all relevant portions of the documentation.

    Update: No additional software is required to enable callbacks. The IA event objects were a red herring. 



  • 3.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 08, 2024 08:40 AM
    Edited by Michael A. Lowry Mar 08, 2024 08:40 AM

    I opened a support ticket for this. I'll post an update when I learn more.



  • 4.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 02:54 AM

    Your body has some JSON formatting issues, namely a missing comma on the end of the "object_name" line and an obsolete comma on the "url"-line. I don't know if this is really the way your payload was sent to Automic by Postman. If so, the "getValidationErrorDetails" (potentially indicating a problem with the JSON parsing) would make sense to me.



    ------------------------------
    ☎️ Swisscom Automation Engineer & 🧙 PE Membership Creator

    Automic Kurse, Tutorials, Tools und mehr auf:
    https://membership.philippelmer.com/
    Zwei Wochen kostenlos testen!
    ------------------------------



  • 5.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 04:03 AM
    Edited by Michael A. Lowry Mar 11, 2024 01:50 PM

    Good catch, @Joel Wiesmann. I should have thought of that, considering the class name involved. 

    With corrected JSON, the AE accepts the execution and returns the associated run ID. However, no callback is logged by the server.

    While the task is still in the EH table, I can see that EH_HasCallback is set to 1, EH_Language is set to E, and EH_StoreName is null. I have not been able to identify another table in the schema that stores additional details about callbacks.

    Aside from the failure to generate a callback, I suspect there's a bug in getValidationErrorDetails. I assume that the intended behavior is that the REST process returns HTTP response code 400 and a more descriptive error message upon encountering JSON validation errors.



  • 6.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 07:29 AM

    Hi Michael

    It works for me (without going into details).

    Are you sure, that there is no networking issue between your Automic infrastructure and your Postman-Endpoint?

    Regards
    Joel



    ------------------------------
    ☎️ Swisscom Automation Engineer & 🧙 PE Membership Creator

    Automic Kurse, Tutorials, Tools und mehr auf:
    https://membership.philippelmer.com/
    Zwei Wochen kostenlos testen!
    ------------------------------



  • 7.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 08:30 AM
    Edited by Michael A. Lowry Mar 11, 2024 11:25 AM

    Thanks for testing it @Joel Wiesmann.

    Looking in the logs, I can see that the callbacks are being performed, evidently by the CALLBACK-1 thread running on the JWP with PER role (periodic tasks).

    WPsrv_EXP2_log_002_00.txt:20240311/085236.844 - 61     U00045159 Thread 'CALLBACK-1'  has ID '129'.
    WPsrv_EXP2_log_002_00.txt:20240311/131033.755 - 129    U00045386 Sending callback with RunId '218987003' at attempt '1' for execution with RunId '218987002'.
    WPsrv_EXP2_log_002_00.txt:20240311/131244.170 - 129    U00045392 Unable to connect to host 'https://XXXXXXXX.mock.pstmn.io/get' for callback with RunId '218987003'.
    ...
    WPsrv_EXP2_log_002_00.txt:20240311/131316.534 - 129    U00045386 Sending callback with RunId '218987003' at attempt '2' for execution with RunId '218987002'.
    WPsrv_EXP2_log_002_00.txt:20240311/131525.962 - 129    U00045392 Unable to connect to host 'https://XXXXXXXX.mock.pstmn.io/get' for callback with RunId '218987003'.
    ...
    WPsrv_EXP2_log_003_00.txt:20240311/090856.588 - 61     U00045159 Thread 'CALLBACK-1'  has ID '73'.
    WPsrv_EXP2_log_003_00.txt:20240311/131736.349 - 73     U00045386 Sending callback with RunId '218987003' at attempt '3' for execution with RunId '218987002'.
    WPsrv_EXP2_log_003_00.txt:20240311/131946.058 - 73     U00045392 Unable to connect to host 'https://XXXXXXXX.mock.pstmn.io/get' for callback with RunId '218987003'.

    I can reach the mock server from the AE host using CURL, so I'm not sure what's going wrong.



  • 8.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 11:10 AM
    Edited by Joel Wiesmann Mar 11, 2024 11:11 AM

    Blind guess: is the (https://xxxxxxxx.mock.pstmn.io/get) certificate possibly self-signed / not trusted by Automic?



    ------------------------------
    ☎️ Swisscom Automation Engineer & 🧙 PE Membership Creator

    Automic Kurse, Tutorials, Tools und mehr auf:
    https://membership.philippelmer.com/
    Zwei Wochen kostenlos testen!
    ------------------------------



  • 9.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 11, 2024 11:50 AM
    Edited by Michael A. Lowry Mar 11, 2024 01:03 PM

    Hi @Joel Wiesmann. The thought occurred to me too, so I tried with normal HTTP. I witnessed no change in behavior. I'll try activating WP tracing to see if I can learn more.

    By the way, callbacks aren't tracked in a separate table because they're tasks in their own right. You can see them by displaying Child Task Executions. The object type of these tasks is CBCK.

    EH_Text contains a copy of the JSON response template defined in the TEMPLATE_EXECUTION entry of UC_CALLBACK_SETTINGS. When the response body is prepared, variables in the template are resolved.


    Update:

    The details of the callback are stored in ACV_Value where ACV_AH_Idnr is the run ID of the callback task and ACV_Name is CALLBACK URL. Here's an example, with line breaks and indentation added for easier reading.

    {
      "type": "http",
      "recurringMode": "once",
      "http": {
        "url": "http://XXXXXXXX.mock.pstmn.io/get",
        "headers": null
      }
    }

    Unlike with most types of executable task, with CBCK tasks the information is not inserted first into ECV before being later moved to ACV. The information just goes straight into ACV when the CBCK task is inserted into EH.

    For what it's worth, ECV & ACV typically store instance parameters of executed tasks. These were originally added specifically for the SAP agent. One can set them manually at execution time using ExecuteObject.setInstanceParameter(). They cannot be read in a task's AE scripting stages like ordinary object or script variables. See this 2014 discussion thread on setInstanceParameter for more details.

    Why write callback details to ACV? I guess the answer is: "Why not?" It's already there, and it's not used for much else.



  • 10.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 12, 2024 12:54 AM
    Edited by Marcin Uracz Mar 12, 2024 01:00 AM

    Hi Michael, 

    Maybe you need to go through a proxy to get into the Internet ? I can imagine that the traffic from commandline could be proxied by default, whereas the one from the callbacks not.

    Cheers,

    Marcin



    ------------------------------
    Cheers,
    Marcin
    ------------------------------



  • 11.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 12, 2024 05:37 AM
    Edited by Michael A. Lowry Mar 12, 2024 05:38 AM

    Thanks, @Marcin Uracz. That's a good point. I explicitly set HTTP_PROXY, HTTP_PROXY, http_proxy, and https_proxy in the script that starts the AE. I confirmed that these are set in the environment of the AE server processes. The problem remains. I'm not sure how to collect additional tracing information for the process that is performing the callback. There might be a special trace flag for this.

    For what it's worth, this SQL will list active callbacks.

    -- List active callbacks
    SELECT EH_Client, EH_AH_Idnr, EH_ParentAct, EH_HostDst, EH_ActivationTime, EH_StartTime,
    EH_Text Response_temlpate, ACV_Value Callback_URL
    FROM EH,ACV WHERE EH_AH_IDNR = ACV_AH_IDNR
    AND EH_Name = 'CALLBACK' AND EH_OType = 'CBCK' AND ACV_VNAME = 'CALLBACK URL'

    I will update the support ticket and see what Broadcom Support recommends.



  • 12.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 13, 2024 02:53 AM
    Edited by Michael A. Lowry Mar 13, 2024 12:28 PM

    @Marcin Uracz: it was the proxy!

    I fixed the connectivity problem by setting the Java system properties http.proxyHost and http.proxyPort in the command that starts the JWPs, E.g.:

    -Dhttp.proxyHost=proxy.mycompany.com -Dhttp.proxyPort=8080

    I confirmed that callbacks are performed by the the JWP with the PER role (periodic tasks).

    Outstanding issues:

    1. The REST Process throws a null pointer exception and returns HTTP response code 500 upon encountering an invalid JSON request body.
    2. The documentation on callbacks should be updated with additional information:
      • how the AE performs callbacks, how to display them in the AWI, and how to get additional details about them;
      • how to specify an HTTP proxy for the JWPs.
    3. If there's a trace flag to enable additional tracing of callbacks, this too should be documented.


  • 13.  RE: AE REST API - Using POST executions endpoint with callback URL
    Best Answer

    Posted Mar 14, 2024 06:26 AM
    Edited by Michael A. Lowry Mar 16, 2024 05:38 AM

    Callbacks in the Automation Engine

    In v21, the AE REST API added an option to define a callback URL when submitting a task for execution. This capability is described on the documentation page Polling and Callback Requests.
     

    Background

    When an external application submits a task for execution in the Automation Engine, the traditional way of monitoring the status of the submitted task is polling. With polling, the external application periodically polls the Automation Engine system to check on the status of the submitted task. This approach comes with disadvantages and trade-offs. If the polling interval is set very low, the external application won't have to wait long to receive status updates. However, a lower polling interval also increases network load and activity in the external application.

    Callbacks (sometimes also called webhooks) offer an alternative and often more efficient approach. Instead of polling every so often to check on the status of a submitted task, the external application runs a listener to wait for the callback. When the tasks completes in the AE system, the AE sends a callback to the executing application, and notifies it of the final status of the task. This eliminates the need for the external application to send repeated requests to check on the status of the task.
     

    Using callbacks

    Callbacks in the Automation Engine work only for tasks submitted via the AE REST API.

    The relevant API is POST /{client_id}​/executions. To enable a callback, just add the callback section to the JSON request body. 

    {
      "object_name": "EBM.TEST.SCRI",
      "callback": {
        "type": "http",
        "recurring_mode": "once",
        "http": {
          "url": "https://xxxxxx.mock.pstmn.io"
        }
      }
    }

     

    The URL to specify is the URL where the external application will listen for callbacks. Typically a callback would be configured to be sent back to the application submitting the execution — or more specifically, to a dedicated callback listener process of the calling application.

    To test the callback capability, you can use the mock server function in Postman.

    (Be sure to consider any firewall between your AE system and the listening application. See Specifying a proxy for callbacks, below.)

    When the task has been successfully activated in the AE, the REST Process will respond with the Run ID of the submitted task.

    {
      "run_id": 219020002
    }

     

    If you display the Child Task Executions. of this task in the AWI, you should see the callback task. All callback tasks have the name CALLBACK and object type CBCK. While the parent task is still running the CALLBACK task will remain in the status Sleeping. When the parent task completes, the AE will mark the callback task Active and perform the callback.

    If the callback listener process of the remote application returns HTTP response code 200, the callback task will be marked ENDED_OK - ended normally. Otherwise, the callback task will be marked ENDED_NOT_OK - aborted. Either way, the status of the callback task has no impact on the originally executed task.

    The callback listener process should receive a JSON payload with information about the completed task.

    {
      "runid": "219020002",
      "object_type": "SCRI",
      "execution_status": "1900",
      "execution_status_text": "ENDED_OK - ended normally",
      "ae_system": "AE_EXP",
      "client_number": "0001",
      "client_description": "",
      "user_department": "MYUSER/TEST",
      "archive_key1": "Test 1",
      "last_error_message": "",
      "last_error_code": "00000000",
      "last_error_insert": ""
    }

     

    Configuring callbacks

    The behavior of callbacks can be configured using the settings in UC_CALLBACK_SETTINGS. E.g., the callback payload can be configured by changing TEMPLATE_EXECUTION. You can add your own custom variables to the template if desired. When the response body is prepared, any AE variables in the template will be resolved.

     

    Implementation details

    Callbacks in the AE DB

    Tasks with a callback have EH_HasCallback=1 set in the EH table. EH_Text contains a a copy of the template used to generate the callback payload. Additional callback details including the callback URL are stored in ACV_Value in the ACV table (where ACV_AH_Idnr is the run ID of the callback task and ACV_Name is CALLBACK URL).

    You can list active & archived callbacks using the following SQL statements.
     

    List active callbacks

    -- List active callbacks
    SELECT EH_Client, EH_AH_Idnr, EH_ParentAct, EH_HostDst, EH_ActivationTime, EH_StartTime,
    EH_Text Response_temlpate, ACV_Value Callback_URL
    FROM EH,ACV WHERE EH_AH_IDNR = ACV_AH_IDNR
    AND EH_Name = 'CALLBACK' AND EH_OType = 'CBCK' AND ACV_VNAME = 'CALLBACK URL'

     

    List archived callbacks

    -- List archived callbacks
    SELECT AH_Client, AH_Status,  AH_Idnr, AH_ParentAct, AH_TimeStamp1, AH_TimeStamp2,
    ACV_Value Callback_URL
    FROM AH,ACV WHERE AH_IDNR = ACV_AH_IDNR
    AND AH_Name = 'CALLBACK' AND AH_OType = 'CBCK' AND ACV_VNAME = 'CALLBACK URL'

     

    Callback handling

    Callbacks are performed by the Java Work Process (JWP) that has been assigned the PER role (periodic tasks). In the log of this JWP, you should see messages like these when callbacks are handled.

    20240311/131735.988 - 61     U00045159 Thread 'CALLBACK-1'  has ID '73'.
    20240311/131736.349 - 73     U00045386 Sending callback with RunId '219020003' at attempt '1' for execution with RunId '219020002'.
    20240311/131736.781 - 73     U00045099 The server replied with following status: '200 OK'
    

    Messages related to callbacks begin with U000453. Responses from the callback listener are recorded in message U400045099.

     

    Specifying a proxy for callbacks

    The JWP that performs callbacks must be able to reach the host specified in the callback URL. If there is a firewall between the JWP and the callback listener process, you must add a firewall rule to allow the callback requests, or you must configure the JWP to use a proxy. To specify a proxy, set the Java system properties http.proxyHost and http.proxyPort in the command that starts the JWP.

    java -Dhttp.proxyHost=proxy.mycompany.com -Dhttp.proxyPort=8080 -jar ucsrvjp.jar -i ucsrv.ini ...

    To use an HTTPS proxy, specify https.proxyHost and https.proxyPort instead.

    java -Dhttps.proxyHost=proxy.mycompany.com -Dhttps.proxyPort=8080 -jar ucsrvjp.jar -i ucsrv.ini ...

    If you want to exclude some hosts or domains from using the proxy, specify http.nonProxyHosts as well.

    -Dhttps.nonProxyHosts="localhost|*.mycompany.com"

    See Java Networking for additional details.



  • 14.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 14, 2024 10:57 AM

    Hi,

    very interesting summary, thank you Michael!

    I have one question: Aren't the active Callbacks in the table ECV? This should actually be the "Activity"-equivalent of the Archive-table ACV -> these table are usually used to store the RA-Attributes of RA-Jobs.



    ------------------------------
    Philipp Elmer

    Become a member!
    https://membership.philippelmer.com
    ------------------------------



  • 15.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 14, 2024 05:36 PM
    Edited by Michael A. Lowry Mar 14, 2024 05:36 PM

    Hi @Philipp Elmer.

    In my tests, I never saw any callback information in ECV. I also found this unusual.



  • 16.  RE: AE REST API - Using POST executions endpoint with callback URL

    Posted Mar 19, 2024 07:32 AM
    Edited by Michael A. Lowry Mar 19, 2024 07:43 AM

    Below is a JSON export of the Postman collection I am using to mock an AE executions callback listener.

    {
    	"info": {
    		"name": "AE executions callback",
    		"description": "Listen and respond to AE execution callbacks.",
    		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    	},
    	"item": [
    		{
    			"name": "Register an AE executions callback",
    			"request": {
    				"auth": {
    					"type": "noauth"
    				},
    				"method": "POST",
    				"header": [
    					{
    						"key": "Content-Type",
    						"value": "application/json"
    					},
    					{
    						"key": "Accept",
    						"value": "application/json"
    					},
    					{
    						"key": "x-mock-response-code",
    						"value": "200",
    						"type": "text"
    					}
    				],
    				"body": {
    					"mode": "raw",
    					"raw": "{\r\n    \"runid\": \"219020002\",\r\n    \"object_type\": \"SCRI\",\r\n    \"execution_status\": \"1900\",\r\n    \"execution_status_text\": \"ENDED_OK - ended normally\",\r\n    \"ae_system\": \"AE_EXP\",\r\n    \"client_number\": \"0001\",\r\n    \"client_description\": \"\",\r\n    \"user_department\": \"MYUSER/TEST\",\r\n    \"archive_key1\": \"Test 1\",\r\n    \"last_error_message\": \"\",\r\n    \"last_error_code\": \"00000000\",\r\n    \"last_error_insert\": \"\"\r\n}",
    					"options": {
    						"raw": {
    							"language": "json"
    						}
    					}
    				},
    				"url": {
    					"raw": "{{MOCK_SERVER}}/ae_executions_callback",
    					"host": [
    						"{{MOCK_SERVER}}"
    					],
    					"path": [
    						"ae_executions_callback"
    					]
    				},
    				"description": "Register an _executions_ API callback from the Automation Engine."
    			},
    			"response": [
    				{
    					"name": "Callback registered successfully",
    					"originalRequest": {
    						"method": "POST",
    						"header": [
    							{
    								"key": "Content-Type",
    								"name": "Content-Type",
    								"value": "application/json",
    								"type": "text"
    							},
    							{
    								"key": "Accept",
    								"value": "application/json"
    							},
    							{
    								"key": "x-mock-response-code",
    								"value": "200",
    								"type": "text"
    							},
    							{
    								"key": "x-api-key",
    								"value": "{{API_KEY}}",
    								"type": "text"
    							}
    						],
    						"body": {
    							"mode": "raw",
    							"raw": "{\r\n    \"runid\": \"219020002\",\r\n    \"object_type\": \"SCRI\",\r\n    \"execution_status\": \"1900\",\r\n    \"execution_status_text\": \"ENDED_OK - ended normally\",\r\n    \"ae_system\": \"AE_EXP\",\r\n    \"client_number\": \"0001\",\r\n    \"client_description\": \"\",\r\n    \"user_department\": \"MYUSER/TEST\",\r\n    \"archive_key1\": \"Test 1\",\r\n    \"last_error_message\": \"\",\r\n    \"last_error_code\": \"00000000\",\r\n    \"last_error_insert\": \"\"\r\n}",
    							"options": {
    								"raw": {
    									"language": "json"
    								}
    							}
    						},
    						"url": {
    							"raw": "{{MOCK_SERVER}}/ae_executions_callback",
    							"host": [
    								"{{MOCK_SERVER}}"
    							],
    							"path": [
    								"ae_executions_callback"
    							]
    						}
    					},
    					"status": "OK",
    					"code": 200,
    					"_postman_previewlanguage": "json",
    					"header": [
    						{
    							"key": "Date",
    							"value": "Thu, 07 Mar 2024 10:30:09 GMT"
    						},
    						{
    							"key": "Content-Type",
    							"value": "application/json"
    						},
    						{
    							"key": "Content-Length",
    							"value": "26"
    						}
    					],
    					"cookie": [],
    					"body": "{\r\n    \"message\": \"Callback registered successfully.\",\r\n    \"callback_payload\": {{$body}}\r\n}"
    				},
    				{
    					"name": "Callback not registered successfully",
    					"originalRequest": {
    						"method": "POST",
    						"header": [
    							{
    								"key": "Content-Type",
    								"name": "Content-Type",
    								"value": "application/json",
    								"type": "text"
    							},
    							{
    								"key": "Accept",
    								"value": "application/json"
    							},
    							{
    								"key": "x-mock-response-code",
    								"value": "404",
    								"type": "text"
    							},
    							{
    								"key": "x-api-key",
    								"value": "{{API_KEY}}",
    								"type": "text"
    							}
    						],
    						"body": {
    							"mode": "raw",
    							"raw": "{\r\n    \"runid\": \"219020002\",\r\n    \"object_type\": \"SCRI\",\r\n    \"execution_status\": \"1900\",\r\n    \"execution_status_text\": \"ENDED_OK - ended normally\",\r\n    \"ae_system\": \"AE_EXP\",\r\n    \"client_number\": \"0001\",\r\n    \"client_description\": \"\",\r\n    \"user_department\": \"MYUSER/TEST\",\r\n    \"archive_key1\": \"Test 1\",\r\n    \"last_error_message\": \"\",\r\n    \"last_error_code\": \"00000000\",\r\n    \"last_error_insert\": \"\"\r\n}",
    							"options": {
    								"raw": {
    									"language": "json"
    								}
    							}
    						},
    						"url": {
    							"raw": "{{MOCK_SERVER}}/ae_executions_callback",
    							"host": [
    								"{{MOCK_SERVER}}"
    							],
    							"path": [
    								"ae_executions_callback"
    							]
    						}
    					},
    					"status": "Not found",
    					"code": 404,
    					"_postman_previewlanguage": "json",
    					"header": [
    						{
    							"key": "Date",
    							"value": "Thu, 07 Mar 2024 10:30:09 GMT"
    						},
    						{
    							"key": "Content-Type",
    							"value": "application/json"
    						},
    						{
    							"key": "Content-Length",
    							"value": "26"
    						}
    					],
    					"cookie": [],
    					"body": "{\r\n    \"message\": \"Run ID could not be associated with a task executed by this application.\",\r\n    \"callback_payload\": {{$body}}\r\n}"
    				}
    			]
    		}
    	],
    	"event": [
    		{
    			"listen": "prerequest",
    			"script": {
    				"type": "text/javascript",
    				"exec": [
    					""
    				]
    			}
    		},
    		{
    			"listen": "test",
    			"script": {
    				"type": "text/javascript",
    				"exec": [
    					""
    				]
    			}
    		}
    	],
    	"variable": [
    		{
    			"key": "API_KEY",
    			"value": "<replcae with your Postman API key.>",
    			"type": "string"
    		},
    		{
    			"key": "MOCK_SERVER",
    			"value": "<replcae with your Postman mock server URL.>",
    			"type": "string"
    		}
    	]
    }

    In a separate collection with the AE REST APIs, I created a new example for the executions endpoint. I modified the JSON body to include the callback:

    {
        "object_name": "EBM.TEST.SCRI",
        "callback": {
            "type": "http",
            "recurring_mode": "once",
            "http": {
                "url": "{{MOCK_SERVER}}/ae_executions_callback",
                "headers": {
                    "x-mock-response-code": "200",
                    "x-api-key": "{{API_KEY}}"
                }
            }
        }
    }

    The x-api-key header is used to grant authorization to a private mock server.

    The x-mock-response-code header serves two purposes:

    • When the mock server receives a request, Postman uses this header to identify which example to match in the collection.
    • The mock server returns the specified HTTP response code to the JWP executing the callback.

    The mock server is configured as follows:

    The AE will mark the callback task ENDED_OK upon receiving any successful (2XX) HTTP response code from the callback listener.

    The body and actual response code of the callback response are evidently discarded. If you want to somehow communicate back from the callback listener to the AE that the callback was not successful, you would have to configure it to return a client error (4XX) response code such as 404. This causes the AE to mark the callback task ENDED_NOT_OK. You might want to do this if the AE callback for some reason includes a Run ID that cannot be associated with a task executed by the external application. (And it might be possible to perform some additional checking of CBCK tasks via AE scripting.) To test this, I created a second executions example wherein x-mock-response-code and the expected response code are set to 404.

    We execute thousands of tasks per day in the AE from external applications. Today, these applications check the status of submitted tasks by periodically  polling the AE DB directly. This allows the external applications to retrieve the current status of many hundreds of tasks in a single transaction. (It also allows us to work around a bug in the TaskFilter class that prevents listing tasks with aliases by their original object names.) With our use cases, switching from polling to callbacks might result in more overhead, not less. Still, it is an interesting new capability.