skip to Main Content

basically I am trying to subscribe for notifications on group changes in order to adjust authorizations in a 3rd party system, find the code below. It uses the graph sdk for Java. I have added the documentation I followed for reference, see Change notification delivery and post subscriptions in Microsoft Docs.

Unfortunately I get a
Invalid event hub notification url. I tried both domain and tenant id, no luck. It doesn’t really surprise me as the notificationUrl really seems odd. Can anyone share some light in here?

       // From https://learn.microsoft.com/de-de/graph/change-notifications-delivery:

        // The main difference during subscription creation will be the notificationUrl. You must set it to
        //  EventHub:https://<azurekeyvaultname>.vault.azure.net/secrets/<secretname>?tenantId=<domainname>, with the following values:

        //   azurekeyvaultname - The name you gave to the key vault when you created it. Can be found in the DNS name.
        //   secretname - The name you gave to the secret when you created it. Can be found on the Azure Key Vault Secrets page.
        //   domainname - The name of your tenant; for example, consto.onmicrosoft.com or contoso.com. Because this domain will be used to access the Azure Key Vault, it is important that it matches the domain used by the Azure subscription that holds the Azure Key Vault. To get this information, you can go to the overview page of the Azure Key Vault you created and click the subscription. The domain name is displayed under the Directory field.

        @GetMapping("/subscribe")
        public void subscribeTochangeNotifications() {
                // following https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0&tabs=http#request-example

                Subscription subscription = new Subscription();
                subscription.changeType = "created,updated";
                subscription.notificationUrl = "EventHub:https://xxxxxxxxx.vault.azure.net/secrets/event-hub-client-secret?tenantId=xxxxxxxxx-xxxx-xxxx-xxxxxxxxx";
                subscription.expirationDateTime = OffsetDateTime.parse("2022-07-05T18:23:45.9356913Z");
                subscription.resource = "/groups";
                subscription.clientState = "SecretClientState";

                azureClient.subscriptions().buildRequest().post(subscription);
        }

Detailed error message is:

nested exception is com.microsoft.graph.http.GraphServiceException: Error code: InvalidRequest
Error message: Invalid event hub notification url='EventHub:https://xxxxxxxxxxxxxxxxx.vault.azure.net/secrets/event-hub-client-secret?tenantId=yyyyyyy-yyy-yyyy-yyyyyyyyyy'.

POST https://graph.microsoft.com/v1.0/subscriptions
SdkVersion : graph-java/v5.30.0
SdkVersion : graph-java/v5.30.0
[...]

400 : Bad Request
[...]

2

Answers


  1. we ran into the same issue (setup with pulumi). Our connection string in the key vault secret was missing the

    ";EntityPath=graphevents" 
    

    at the end.

    Login or Signup to reply.
  2. @Wilberforce, I had the same issue and figured out that I missed Event Hub creation in the EventHub namespace which caused connection string isn’t valid. After you created a EventHub namespace, you also need to create a EventHub at "Event Hubs" tab, create a new policy under "shared access Policies" from created Event hub page and then copy the connection string from there. make sure your Event hub connection string like below

    Endpoint=sb://<NamespaceName>.servicebus.windows.net/;SharedAccessKeyName=<KeyName>;SharedAccessKey=<KeyValue>;EntityPath=<EventHubName>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search