Select to view content in your preferred language

Getting Started with Feature Service Webhooks

6094
20
Jump to solution
07-14-2023 01:20 PM
ZachBodenner
MVP Regular Contributor

Hello, 

I've been excited to start working with webhooks to automate email communication. However, I need a little help. In the past, I've built a webhook in Power Automate to send emails when a survey 123 response is submitted, but I want to to use Feature Service Webhooks in 11.1 to track other things like updated/edited features. There are some parameters in the setup that I've been unable to figure out how to enter. For starters, the webhook creator in the server admin wants a hook url. How do I even find that? From what I understand, I create a webhook here, and then go in to power automate a figure out what to do with the payload, right? Is there a list of hook urls that I should have found somewhere?

0 Kudos
20 Replies
ZachBodenner
MVP Regular Contributor

Sure, so here's the body, following along with this walkthrough:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "layerId": {
                "type": "integer"
            },
            "orgId": {
                "type": "string"
            },
            "serviceName": {
                "type": "string"
            },
            "lastUpdatedTime": {
                "type": "integer"
            },
            "changesUrl": {
                "type": "string"
            },
            "events": {
                "type": "array",
                "items": {
                    "type": "string"
                }
            }
        },
        "required": [
            "name",
            "layerId",
            "orgId",
            "serviceName",
            "lastUpdatedTime",
            "changesUrl",
            "events"
        ]
    }
}
 
When I replace that with your basic body above, the hook works:
 
ZachBodenner_0-1689779965756.png

So there's got to be something related to the body provided in that walkthrough?

0 Kudos
ZachBodenner
MVP Regular Contributor

Here's my body, from this walkthrough:

 

{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"layerId": {
"type": "integer"
},
"orgId": {
"type": "string"
},
"serviceName": {
"type": "string"
},
"lastUpdatedTime": {
"type": "integer"
},
"changesUrl": {
"type": "string"
},
"events": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"name",
"layerId",
"orgId",
"serviceName",
"lastUpdatedTime",
"changesUrl",
"events"
]
}
}

 

When I replace with your simple body above, it works! 

ZachBodenner_0-1689780327040.png

So it must be something about the body from the walkthrough? Of note, as discussed above the walkthrough is for hosted layers in ArcGIS Online, but I'm working against a referenced feature service on a federated hosting server in Enterprise. Possible that the properties called must be different? I don't know where to look for a correct list.

 

0 Kudos
KevinHibma
Esri Regular Contributor

That's good news Zach!

The blog you have is in invaluable walk-through if you're wanting to extract changes out of the extract changes API. There are some small differences between Online and Enterprise, but that blog for the most part should hold up. Looking at that sample JSON, that "required" section concerns me. I wonder if that is Power Automate's way of saying "if the incoming payload does NOT have those fields, send an error response back", and in turn, the webhook cannot create.

The benefit to supply a JSON schema into the HTTP request is received sets up the next connectors with what comes previously, basically making it easier to build up the flow.

If you want, try this JSON schema. This is specific to Enterprise Feature Service webhooks, without the required parameters. 

 

{
"type": "object",
"properties": {
"serviceType": {
"type": "string"
},
"changesUrl": {
"type": "string"
},
"name": {
"type": "string"
},
"id": {
"type": "string"
},
"folderName": {
"type": "string"
},
"serviceName": {
"type": "string"
},
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"eventType": {
"type": "string"
},
"when": {
"type": "integer"
}
}
}
}
}
}

 

 

0 Kudos
ZachBodenner
MVP Regular Contributor

Hey, that JSON schema works! Now just to actually test out edits to the feature class and figure out how to get the actual information I want when changes are made. 

0 Kudos
KevinHibma
Esri Regular Contributor

Good to hear. I forgot, I actually have this documented at https://github.com/Esri/webhooks-samples/tree/master/3rdParty/PowerAutomate  (I just updated the JSON schema, removing required from all of them). This link would be a good place to start if someone happens upon this thread in the future.

I'll try to get a blog out that builds on the initial one, more focused on Enterprise.

thanks for working through this, Zach.

0 Kudos
ZachBodenner
MVP Regular Contributor

That'd be great, thanks! Especially if it included any additional info on pulling fields, with a bonus on getting them in a readable format as opposed to a json string. I want to be able to trigger emails to send to others in my organization that might not be so tech savvy.

0 Kudos
ZachBodenner
MVP Regular Contributor

Also, even though you deduced a solution to the first problem, I might ask another question or two of you here because you seem very willing and able to help! So I've been getting run errors in Power Automate in the Generate Server Token Step:

 

ZachBodenner_0-1689796930312.png

"Unable to process template language expressions in action 'Generate_Server_Token' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#first for usage details.'."

This is one other step that was tripping me up in the construction of the flow. I think I have the right URL for server tokens, but I'm not as sure as I am as in the Portal Token step where I'm very confident the URL is right.

Here's what the walkthrough says to add on the body of the Generate Server Token:

f=json&token=@{body('Portal_Token_Response')?['token']}&serverURL=@{decodeUriComponent(first(triggerBody())['changesUrl'])}

So it does use the f/first function, which PA says should be an array or string, but the next parse json step specifically calls for an object schema.

 

0 Kudos
KevinHibma
Esri Regular Contributor

Zach,

My Generate Token looks like the following. This is a bit different from yours. You'll notice I've hard coded a username/password in. I'm not real sure about the errors you're getting.

I'll point out 2 things -- 1) If you make your feature service public, you can probably skip the token. 2) I see you pointing to port :6080 -- this makes use of a self-signed cert that will cause security warnings. PA might not like communicating with something that is not "Secure". Can you point at your fully qualified web adaptor URL?

KevinHibma_0-1689797740033.png

 

I've extract my test flow and attached it here as a zip. You can try importing it into your environment. The places you'll need to update:

  • On import you'll need to connect it to your 365 account
  • Generate token: url, username, password
  • Inside "check status until ready", you'll need to update the URI in the Check Status (Click the "concat" and update the URL in the expression)
  • Apply to each > Email. You'll need to update the send email address

 

 

0 Kudos
ZachBodenner
MVP Regular Contributor

Sure, I'll give it a whirl tomorrow. I see in your screenshot that the URI looks like it's targeting a Portal? My flow made it past the Portal token and got hung up on the server token. I wouldn't use the same URL in both, would I?

This particular service is public, but I want to enable these hooks for secure services as well. Would I be able to generate a server token through a web adaptor, or do I need something like https://FQDN:6443/arcgis/tokens/generateToken?

0 Kudos
KevinHibma
Esri Regular Contributor

Sorry, I sometimes take for granted I use the Primary Site Administrator account which allows me to do anything, anywhere (generally speaking).

You can use the Portal Gen Token to request a server token, although that becomes a 2nd call trading portal for server. Or you should just be able to use a server token generation call: https://developers.arcgis.com/rest/enterprise-administration/server/generatetoken.htm To answer your question, yes, I believe you should be able to request a token through your web adaptor without any issues.

0 Kudos