Hi @Agrawal, Amit , yes this should be possible! However, as you mentioned, if the resource and change type are the same for a subscription payload, it is considered a duplicate subscription. You can avoid this by adding a custom header to each subscription request with a unique identifier for that subscription. This way even if the resource and change type are the same, the subscription will be considered unique because of the custom header.
Here is an example of how to do this:
import (
"net/http"
"fmt"
"bytes"
)
func createSubscription() {
url := "https://graph.microsoft.com/v1.0/subscriptions"
// Define the subscription payload
subscription := map[string]interface{}{
"changeType": "created",
"notificationUrl": "https://myapp.azurewebsites.net/api/notifications",
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": "2022-01-01T11:23:45.6789012Z",
}
// Convert the subscription payload to JSON
jsonPayload, err := json.Marshal(subscription)
if err != nil {
fmt.Println(err)
return
}
// Create a new HTTP request with the subscription payload
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload))
if err != nil {
fmt.Println(err)
return
}
// Add a custom header to the request with a unique identifier for the subscription
req.Header.Set("My-Subscription-Id", "123456")
// Send the request and handle the response
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
// Handle the response
if resp.StatusCode == http.StatusCreated {
fmt.Println("Subscription created successfully")
} else {
fmt.Println("Error creating subscription")
}
}
The custom header "My-Subscription-Id" is added to the subscription request with a unique identifier for the subscription. This way, even if the resource and change type are the same for multiple subscriptions, each subscription will be considered unique because of the custom header.
Please let me know if you have any questions and I can help you further.
If this answer helps you please mark "Accept Answer" so other users can reference it.
Thank you,
James