cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ruprect
Frequent Visitor

Create ServiceEndpoint and SdkMessageProcessingSteps after deployment of ARM template

Hi all,

I want to streamline my deployments, and have therefore created a PowerShell script that deploys an ARM template to Azure, and then have some output parameters that I would like to use to do the following:

 

  1. Create a ServiceEndpoint
  2. Create Steps:
    1. Listen on Update of entity Contact, on fields firstname and lastname

My problem is the final step - When creating Steps - An error is returned.

 

First off, here is my PowerShell script - I'll explain my steps afterwards:

 

 

# Perform deployment
$deploymentOutput =  az deployment group create --name $deploymentName --resource-group $resourceGroup --template-file ".\$deploymentFolder\azuredeploy.json" --parameters ".\$deploymentFolder\azuredeploy.parameters.$environmentName.json" --output json | ConvertFrom-Json

# Check deployment output structure
if ($deploymentOutput -and $deploymentOutput.properties -and $deploymentOutput.properties.outputs -and $deploymentOutput.properties.outputs.'ServiceBus-PrimaryKey' -and $deploymentOutput.properties.outputs.'ServiceBus-PrimaryKey'.value) {
    $confirmation = Read-Host "Do you want to register a webhook within Dataverse? (yes/no)"
    if ($confirmation -ne "yes") {
        Write-Host "`nDeployment complete - Webhook skipped."
        exit
    }

    # Extract necessary values
    $primaryKey = $deploymentOutput.properties.outputs.'ServiceBus-PrimaryKey'.value
    $serviceBusName = $deploymentOutput.properties.outputs.'ServiceBus-Name'.value
    $keyVaultName = $deploymentOutput.properties.outputs.keyvaultName.value

    # Retrieve secrets from Key Vault
    Write-Output "`nRetrieving secrets..."
    $secrets = @{}
    @('CRM-ClientId', 'CRM-Secret', 'CRM-TenantId', 'CRM-Endpoint') | ForEach-Object {
        Write-Host -NoNewline "."
        $secrets[$_] = (az keyvault secret show --vault-name $keyVaultName --name $_ --query "value" -o tsv)
    }

    $clientId = $secrets['CRM-ClientId']
    $clientSecret = $secrets['CRM-Secret']
    $tenantId = $secrets['CRM-TenantId']
    $dataverseUrl = $secrets['CRM-Endpoint']

    # Define Dataverse environment URL and authentication profile name
    $envName = "PAC-$environmentName"

    # Authenticate to Dataverse using PAC CLI
    #Write-Output "`nAuthenticating PAC"
    #pac auth create --environment $dataverseUrl --tenant $tenantId --applicationid $clientId --clientSecret $clientSecret --name $envName

    # Get access token using Azure AD App details
    $tokenResponse = Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -ContentType "application/x-www-form-urlencoded" -Body @{
        client_id     = $clientId
        client_secret = $clientSecret
        scope         = "$dataverseUrl/.default"
        grant_type    = "client_credentials"
    }

    $accessToken = $tokenResponse.access_token
    $webhookName = "Integration-ServiceBUS"
    $serviceBusUrl = "sb://$serviceBusName.servicebus.windows.net"

    # Check if the webhook already exists
    $existingWebhook = Invoke-RestMethod -Method Get -Uri "$dataverseUrl/api/data/v9.2/serviceendpoints?`$filter=name eq '$webhookName'" -Headers @{
        Authorization = "Bearer $accessToken"
    }

    # Define the payload for the webhook registration
    $webhookPayload = @{
        messageformat    = 2
        name             = $webhookName
        contract         = 6
        authtype         = 2
        saskeyname       = "DataverseSender"
        saskey           = $primaryKey
        namespaceaddress = $serviceBusUrl
        solutionnamespace= $serviceBusName
        description      = "Service Endpoint for ServiceBUS"
        path             = "crm-contact-changed"
        namespaceformat  = 2
    } | ConvertTo-Json -Depth 10

    # Either PATCH existing or POST new
    if ($existingWebhook.value.Count -gt 0) {
        Write-Output "Service Endpoint already exists - Patching"
        $serviceEndpointId = $existingWebhook.value[0].serviceendpointid
        Invoke-RestMethod -Method Patch -Uri "$dataverseUrl/api/data/v9.2/serviceendpoints($serviceEndpointId)" -Headers @{
            Authorization = "Bearer $accessToken"
            "Content-Type" = "application/json"
            "If-Match" = "*"
        } -Body $webhookPayload
        Write-Output "Webhook updated successfully."
    } else {
        Write-Output "Service Endpoint was not found - Creating new"
        Invoke-RestMethod -Method Post -Uri "$dataverseUrl/api/data/v9.2/serviceendpoints" -Headers @{
            Authorization = "Bearer $accessToken"
            "Content-Type" = "application/json"
        } -Body $webhookPayload
        Write-Output "Webhook created successfully."
    }

} else {
    Write-Output $deploymentOutput
    Write-Output "`nThe expected output structure is not present. Please check the deployment output."
}

 

 

 

My ARM template creates a ServiceBus, a Key Vault and other resources. After creation I get some output parameters, among those is the ServiceBus endpoint, ServiceBus name and Key Vault name. And that is used by the PowerShell script to create the ServiceEndpoint.

 

Using Plugin Registration Tool (PAC Tool PRT) I am able to see my ServiceEndpoint:

Ruprect_0-1719495387211.png

However when I try to create the SdkMessageProcessingSteps I have the following PayLoad:

 

{
    "supporteddeployment": 0,
    "stage": 40,
    "statuscode": 1,
    "customizationlevel": 1,
    "description": "Integration-ServiceBUS: Update of contact",
    "statecode": 0,
    "rank": 1,
    "asyncautodelete": true,
    "name": "Integration-ServiceBUS: Update of contact",
    "solutionid": "fd140aae-4df4-11dd-bd17-0019b9312238",
    "ismanaged": false,
    "versionnumber": 332817509,
    "mode": 1,
    "introducedversion": "1.0",
    "canbebypassed": false,
    "filteringattributes": "firstname,lastname",
    "enablepluginprofiler": false,
    "componentstate": 0,
    "canusereadonlyconnection": false,
    "eventexpander": null,
    "configuration": null,
    "category": null,
    "plugintypeid@odata.bind": "/plugintypes(ef521e63-cd2b-4170-99f6-447466a7161e)",
    "sdkmessageid@odata.bind": "/sdkmessages(20bebb1b-ea3e-db11-86a7-000a3a5473e8)"
}

 

The PluginTypeId is Microsoft.Crm.ServiceBus.ServiceBusPlugin (found by querying 

"https://xxxxx.api.crm4.dynamics.com/api/data/v9.2/plugintypes" and searching for the name:
Ruprect_1-1719495685384.png

And SdkMessageId is "Update":

Ruprect_2-1719495775966.png

However the error I get is this:

 

{
    "error": {
        "code": "0x80040256",
        "message": "Action failed for assembly 'Microsoft.Crm.ServiceBus, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35': No publisher is found, assembly must be registered in isolation."
    }
}

 

 

So if anyone has created the Steps through API - Any help would be appreciated.

 

I am able to create the step in Plugin Registration Tool (not through XRM toolkit):

Ruprect_3-1719495984293.png

But not by REST Api

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ruprect
Frequent Visitor

@parvezghumra 

I finally found my missing parameter, on the following article: https://devblogs.microsoft.com/ise/registering-plugins-in-dataverse/ there was a description of fields necessary.

 

And my missing parameters was :

 

"eventhandler_serviceendpoint@odata.bind":"/serviceendpoints(a1842d7d-6e36-ef11-8409-7c1e521fb863)",
"sdkmessagefilterid@odata.bind": "/sdkmessagefilters(83c9bb1b-ea3e-db11-86a7-000a3a5473e8)",

 

 

The EventHandler is the ServiceBus reference, and the SDK message filter Id is the Entity I wish to subscribe to - In this case "Contact".

 

So my final payload to register the Step is:

 

{
    "name": "Integration-ServiceBUS: Update of contact",
    "description": "Integration-ServiceBUS: Update of contact",
    "eventhandler_serviceendpoint@odata.bind":"/serviceendpoints(512414c1-7434-ef11-8409-000d3ab2c00a)",
    "sdkmessageid@odata.bind": "/sdkmessages(20bebb1b-ea3e-db11-86a7-000a3a5473e8)",
    "plugintypeid@odata.bind": "/plugintypes(ef521e63-cd2b-4170-99f6-447466a7161e)",
    "sdkmessagefilterid@odata.bind": "/sdkmessagefilters(83c9bb1b-ea3e-db11-86a7-000a3a5473e8)",
    "supporteddeployment": 0,
    "asyncautodelete": true,
    "filteringattributes": "firstname,lastname",
    "rank": 1,
    "stage": 40,
    "statuscode": 1,
    "mode": 1
}

 

And this creates my much wanted Processing Step on my ServiceEndpoint

View solution in original post

5 REPLIES 5
parvezghumra
Most Valuable Professional
Most Valuable Professional

@Ruprect Are you using the same user account to register the SDK Message Processing Step via the Web API as you do when you're doing it using the Plugin Registration Tool? Does that user have System Administrator privileges?




Parvez Ghumra, XRM Solutions UK
Microsoft Business Applications MVP | Power Platform | Dynamics 365 CE/CRM | Azure - Developer | Technical Consultant | Technical Architect | Community Super User | User Group Co-Organizer | Blogger

If this response helped you in any way, please give kudos by clicking the 'Thumbs Up'/'Like' button and/or marking it as an 'Accepted Solution'. This helps others by providing a quick way to identify likely solutions to their issues.

Also, for more useful content, please free to add me as a friend on this forum, follow my blog, follow me on Twitter and connect with me on LinkedIn

@parvezghumra Originally I used a licenced user in Plugin Registration Tool, and an App Registration in Postman, but I have also tried with the same licensed user in Postman - To no avail.

 

It might be some part of the payload I've missed, but if I remove the plugintypeid@odata.bind or the sdkmessageid@odata.bind I get a missing parameter error:

 

{
    "error": {
        "code": "0x80040200",
        "message": "plugintypeid is missing."
    }
}
parvezghumra
Most Valuable Professional
Most Valuable Professional

@Ruprect If you are trying to do this for deployment reasons via the Web API, I would recommend deploying the ServiceEndpoint and SDK Message Processing Step as part of a managed solution deployment instead. This way the objects will be in a managed state.




Parvez Ghumra, XRM Solutions UK
Microsoft Business Applications MVP | Power Platform | Dynamics 365 CE/CRM | Azure - Developer | Technical Consultant | Technical Architect | Community Super User | User Group Co-Organizer | Blogger

If this response helped you in any way, please give kudos by clicking the 'Thumbs Up'/'Like' button and/or marking it as an 'Accepted Solution'. This helps others by providing a quick way to identify likely solutions to their issues.

Also, for more useful content, please free to add me as a friend on this forum, follow my blog, follow me on Twitter and connect with me on LinkedIn

@parvezghumra 

 

The final deployment will be part of a managed solution.

 

However, I would like to create the ServiceEndpoint - And Plugin Steps through API to do it at the same time as my ARM template is deployed. After creation it will be added to the solution, which will then be deployed onto production as managed.

Ruprect
Frequent Visitor

@parvezghumra 

I finally found my missing parameter, on the following article: https://devblogs.microsoft.com/ise/registering-plugins-in-dataverse/ there was a description of fields necessary.

 

And my missing parameters was :

 

"eventhandler_serviceendpoint@odata.bind":"/serviceendpoints(a1842d7d-6e36-ef11-8409-7c1e521fb863)",
"sdkmessagefilterid@odata.bind": "/sdkmessagefilters(83c9bb1b-ea3e-db11-86a7-000a3a5473e8)",

 

 

The EventHandler is the ServiceBus reference, and the SDK message filter Id is the Entity I wish to subscribe to - In this case "Contact".

 

So my final payload to register the Step is:

 

{
    "name": "Integration-ServiceBUS: Update of contact",
    "description": "Integration-ServiceBUS: Update of contact",
    "eventhandler_serviceendpoint@odata.bind":"/serviceendpoints(512414c1-7434-ef11-8409-000d3ab2c00a)",
    "sdkmessageid@odata.bind": "/sdkmessages(20bebb1b-ea3e-db11-86a7-000a3a5473e8)",
    "plugintypeid@odata.bind": "/plugintypes(ef521e63-cd2b-4170-99f6-447466a7161e)",
    "sdkmessagefilterid@odata.bind": "/sdkmessagefilters(83c9bb1b-ea3e-db11-86a7-000a3a5473e8)",
    "supporteddeployment": 0,
    "asyncautodelete": true,
    "filteringattributes": "firstname,lastname",
    "rank": 1,
    "stage": 40,
    "statuscode": 1,
    "mode": 1
}

 

And this creates my much wanted Processing Step on my ServiceEndpoint

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages