Trouble with creating Microsoft Graph Partner Topic

Nemanja Jovic 20 Reputation points MVP
2023-09-19T14:16:55.5466667+00:00

Hi all,

I am trying to create a Graph Partner Topic for the Event Grid. I succeeded in yesterday's deployment to West Europe, and today, when I tried a different region, it stated that the partner topic already exists in a different location.

I cleaned all subscriptions/topics using the MSGraph PowerShell Module.

At the moment, Get-MgSubscription does not return any value.

Here's the script I am using to provision the partner topic.

param(
    [string]$TenantId,
    [string]$SubscriptionId,
    [string]$ResourceGroupName,
    [string]$Location,
    [string]$ClientId,
    [string]$ClientSecret
  )
  $url = "https://login.microsoftonline.com/$TenantId/oauth2/token"
  $Body = @{
    grant_type    = 'client_credentials'
    client_id     = $ClientId
    client_secret = $ClientSecret
    resource      = 'https://graph.microsoft.com'
  }
  $accessToken = (Invoke-RestMethod -Method Post -Uri $URL -Body $Body).access_token
  $dateTime = (Get-Date).AddMinutes(4230).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssK")
  $uri = "https://graph.microsoft.com/beta/subscriptions"
  $Headers = @{
      "Authorization" = "Bearer $AccessToken"
      "x-ms-enable-features" = "EventGrid"
  }
  $Body = @{
      changeType = "Updated,Deleted,Created"
      notificationUrl = "EventGrid:?azuresubscriptionid=$SubscriptionId&resourcegroup=$ResourceGroupName&partnertopic=default&location=$Location"
      resource = "users"
      expirationDateTime = $dateTime
      clientState = "mysecret"
  } | ConvertTo-Json
  Invoke-RestMethod -Uri $URI -Headers $Headers -Body $Body -Method POST -ContentType "application/json"

This is the error I am receiving from the API

Invoke-RestMethod -Uri $URI -Headers $Headers -Body $Body -Method P …
     |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"error":{"code":"StoreBadRequest","message":"The specified partner topic already exists in a different
     | location.","innerError":{"date":"2023-09-19T14:11:06","request-id":"7ce8023d-74bf-404e-bd7a-3c51db7151a1","client-request-id":"7ce8023d-74bf-404e-bd7a-3c51db7151a1"}}
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,983 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
330 questions
{count} votes

Accepted answer
  1. Danstan Onyango 3,816 Reputation points Microsoft Employee
    2023-09-25T10:42:18.13+00:00

    As per the docs - Receive Microsoft Graph change notifications through Azure Event Grid (preview), Quoting

    • Partner topic names must be unique within the same Azure region. Each tenant-application ID combination can create up to 10 unique partner topics.
    • Be mindful of certain Graph API resources' service limits when developing your solution.

    To solve the error, you need to delete the partner topic and recreate in the new region or use a different name. See payload below

    {
        "notificationUrl": "EventGrid:?azuresubscriptionid=33bf8f68-1bd8-4408-90af-157bb367f97d&resourcegroup=community&partnertopic={Uniqueue/DeleteExisting}&location=eastus",
        "resource": "users",
        "changeType": "Updated,Deleted,Created",
        "expirationDateTime": "2023-09-28T08:01:32Z",
        "clientState": "mysecret"
    }
    

    You can do so under https://portal.azure.com/#view/Microsoft_Azure_EventGrid/EventGridCentralMenuBlade/~/partner_topics
    See screenshot below.
    User's image

    As an alternative you can use a different partner topic from in each region. Like topic-name-region but I don't know how this will work in your scenario.
    I believe you can delete that resource using AZ PowerShell module in you script for automation.


0 additional answers

Sort by: Most helpful