'Error 'Invalid hostname for this tenancy' on using graph api of sharepoint to subscribe event notification

I am new to sharepoint and now I am trying to create a webhook for my sharepoint sites, such that on any crud operation i would get notification in my app

I have created a webapp to receive notification and console application to subscribe notification, I used Microsoft graph api by referring this document to create subscription

Now the issue is when i give following in my subscription request body

Resource = "sites/{siteName}/lists/{listId}"

It does hit in my notification web app from where i respond 200 ok, but then in my console web application it throws error saying "Invalid hostname for this tenancy"

I am not sure about my resource id, is there any suggestion for my SharePoint site resource



Solution 1:[1]

Generally you would get this error when your hostname is wrong. For ex: here is the valid way of getting a site

var site = await graphClient.Sites.GetByPath("/sites/{siteName}","{companyName}.sharepoint.com");

We should not add https:// in the hostname.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 san