title: Creating an Azure Event Grid Topic Error - "does not have authorization to perform action"
body: <p>I'm writing a python script that is intended to create Event Grid Topics.</p>
  
  <p>I'm following a couple of Microsoft tutorials and Github repos and have written some python code to create topics. </p>
  
  <hr>
  
  <p>Python samples: <a href="https://docs.microsoft.com/en-us/samples/azure-samples/event-grid-python-public-consume-events/event-grid-python-public-consume-events/" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/samples/azure-samples/event-grid-python-public-consume-events/event-grid-python-public-consume-events/</a></p>
  
  <p>Github Repos: <a href="https://github.com/Azure-Samples/event-grid-python-public-consume-events" rel="nofollow noreferrer">https://github.com/Azure-Samples/event-grid-python-public-consume-events</a></p>
  
  <p>Azure Service Principal: <a href="https://azure.microsoft.com/documentation/articles/resource-group-create-service-principal-portal" rel="nofollow noreferrer">https://azure.microsoft.com/documentation/articles/resource-group-create-service-principal-portal</a></p>
  
  <hr>
  
  <p>I've come up with this python code:</p>
  
  <pre><code>def CreateOrUpdateTopics(subscriptionId, clientId, clientSecret,tenantId,resourceGroup,location, topics):   
  
          credentials = ServicePrincipalCredentials(
              client_id=clientId,
              secret=clientSecret,
              tenant=tenantId
              )
  
          print("\nCreate event grid management client")
          event_grid_client = EventGridManagementClient(credentials, subscriptionId)
  
          for topic in topics:
              print(f'\nCreating EventGrid topic {topic}')
              topic_result_poller = event_grid_client.topics.create_or_update(resourceGroup,
                                                                       topic,
                                                                       Topic(
                                                                           location=location,
                                                                           tags={'createdBy': 'MCCC'}
                                                                       ))
              # Blocking call            
              topic_result = topic_result_poller.result()
  
              ## ERROR SHOWS UP HERE
              print(topic_result)
  </code></pre>
  
  <p>When I execute the code I receive a message </p>
  
  <blockquote>
    <p>The client 'zzzz' with object id 'zzzz' does not have authorization to
    perform action 'Microsoft.EventGrid/topics/write' over scope
    '/subscriptions/zzz/resourceGroups/MCCC-RG/providers/Microsoft.EventGrid/topics/Temperature'
    or the scope is invalid. If access was recently granted, please
    refresh your credentials.</p>
  </blockquote>
  
  <p>I registered a new app in Azure Active Directory:</p>
  
  <p><a href="https://i.stack.imgur.com/UMNFR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UMNFR.png" alt="enter image description here"></a></p>
  
  <p>I've also assigned a role to the resource group for the SP.</p>
  
  <p><a href="https://i.stack.imgur.com/3dAEk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3dAEk.png" alt="enter image description here"></a></p>
  
  <p>It seems like i'm missing some role access on my service principle though I can't seem to find a reference to what it should be.</p>
  
  <p>Could you please point me in the right direction?</p>