Webhook Request URL with Parameter

I need to create a Webhook to request external Web API to send Item data to external system
in current implmentation the Webhook request URL look like this “http://Domain:port/API/Item/”
but the Owner of the Web API asked to make webhook Request URL to include “item_code” value
to look like this “http://Domain:port/API/Item/{@item_code}”

how can I do that ?

This may help Restful api calls and passing parameters

When defining a WebHook you can send DocType values like “item_code” by bracketing them as variables. So for example, in a WebHook I am preparing I send a JSON Request body like this …

{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiaWF0IjoxNTg4Nzc0Mzc2LCJleHAiOjI1MjE4OTQzNzZ9.YZLN2tXq0NRNMwQK50Wx66f4xJ2-eAT3TSj9e_FLhKA",
    "doctype": "{{doc.doctype}}",
    "data": {
        "tax_id": "{{doc.tax_id}}",
        "name": "{{doc.name}}"
    }
}

Your need, if I understand you, is different. You are being forced to place a DocType value in the URL.

Here is a curl command I use to create a WebHook:

curl -X POST 'http://einvoice/api/resource/Webhook' \
-H 'Authorization: token 0969b1676d6f050:b96c30d4b1d5914' \
-H 'Content-Type: application/json' \
-d '{
     "naming_series": "EINV-.####",
     "webhook_doctype": "Sales Invoice",
     "webhook_docevent": "on_change",
     "condition": "doc.xml_file==\"Home\"",
     "request_url": "http://einvoice.myhost.io/einvsvc/einv/create",
     "request_structure": "JSON",
     "webhook_json": "{
          \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NywiaWF0IjoxNTg4Nzc0Mzc2LCJleHAiOjI1MjE4OTQzNzZ9.YZLN2tXq0NRNMwQK50Wx66f4xJ2-eAT3TSj9e_FLhKA\",
          \"doctype\": \"{{doc.doctype}}\",
          \"data\": {
              \"tax_id\": \"{{doc.tax_id}}\",
              \"name\": \"{{doc.name}}\"
          }
      }",
      "webhook_headers": [
         {
            "key": "Content-Type",
            "value": "application/json"
         }
     ],
     "webhook_data": []
}'

I expect you can see the line that specifies the remote API endpoint:

     "request_url": "http://einvoice.myhost.io/einvsvc/einv/create",

In a typical API your URL would be …

http://Domain:port/API/Item/

… and the variable values would be sent as POST body values.

However you are being required to achieve something like:

http://Domain:port/API/Item/{@GOOFY_ITEM_44_00737}

Do I have that right?

Something you might try, although I have no idea if it would work, is to URL Encode the characters “{”, “@” and “}” (“%7B”, “%40” and “%7D”) and then use a template variable in between. So … the URL would be:

http://Domain:port/API/Item/%7B%40{{doc.item_code}}%7D

I am certain template variable expansion is done for the contents of the webhook_json parameter, but I do not know if it also done for the request_url parameter.

If not…

You might have to set up a tiny middleware server. Your WebHook request_url would point to your middleware which would transpose your webhook_json into the onward request URL.

Does that make any sense?