Skip to content

Conversation

@sdelgadoc
Copy link
Contributor

Per @alejcas request in PR: #1137, I am adding subscription functionality for:

  • List subscriptions
  • Get subscription
  • Update subscription

Also updated example to support new subscriptions calling convention.

CC: @kwilsonmg

@RogerSelwyn
Copy link
Contributor

@alejcas we could do with a section in the docs on subscriptions. I’ll be back home next week and am happy to structure the content. Should it just mirror what is in the examples here? Or anything else needed?

@alejcas
Copy link
Member

alejcas commented Dec 10, 2025

@alejcas we could do with a section in the docs on subscriptions. I’ll be back home next week and am happy to structure the content. Should it just mirror what is in the examples here? Or anything else needed?

Thanks! That will be great.
It's just a general description of what a subscription is (and a link to the ms graph docs for example: https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0) and the example provided in the example folders.
It can be extended with what's currently possible with the O365 implemented methods.

@alejcas
Copy link
Member

alejcas commented Dec 10, 2025

Per @alejcas request in PR: #1137, I am adding subscription functionality for:

  • List subscriptions
  • Get subscription
  • Update subscription

Also updated example to support new subscriptions calling convention.

CC: @kwilsonmg

Great! I'll merge it. Thanks

@alejcas alejcas merged commit 6716030 into O365:master Dec 10, 2025
@sdelgadoc
Copy link
Contributor Author

@alejcas we could do with a section in the docs on subscriptions. I’ll be back home next week and am happy to structure the content. Should it just mirror what is in the examples here? Or anything else needed?

Thanks! That will be great. It's just a general description of what a subscription is (and a link to the ms graph docs for example: https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0) and the example provided in the example folders. It can be extended with what's currently possible with the O365 implemented methods.

@RogerSelwyn, it might be helpful to, along with the link to MS Graph docs link recommended by @alejcas above, include the following link to the more tutorial-style article on how to use subscriptions. It was very helpful for me, when I was trying to figure out how they worked, so I could add the functionality.

Receive change notifications through webhooks
https://learn.microsoft.com/en-us/graph/change-notifications-delivery-webhooks?tabs=http

@RogerSelwyn
Copy link
Contributor

I've started to create the docs (sorry slightly delayed due to issues with flooding at our property). I've taken the content provided so far, but to be honest I need to have a go myself so I can understand how it works and the structure the example with some extra guidance.

The doc so far is here - https://github.com/RogerSelwyn/python-o365/blob/subscription-docs/docs/source/usage/subscriptions.rst. PR in draft is here - #1201

@sdelgadoc
Copy link
Contributor Author

Thanks @RogerSelwyn! I took a look at the draft and I think it's a really good start. I have a few edits, Would you rather I provide comments on the PR for you to implement, or make the changes directly on the PR?

P,S, I'm sorry to hear about the flooding. 👎

@RogerSelwyn
Copy link
Contributor

If you can make changes on the PR feel free, not sure if you will have permission though.

@RogerSelwyn
Copy link
Contributor

@sdelgadoc Testing this I get the below error when trying to delete or renew the subscription:

192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 1536, in __call__
    return self.wsgi_app(environ, start_response)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 1514, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/roger/Documents/Development/GitHub/python-o365/.venv/lib/python3.13/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/roger/Documents/Development/GitHub/python-o365/tests/test_subscriptions.py", line 95, in delete_subscription
    deleted = account.subscriptions().delete_subscription(subscription_id)
  File "/Users/roger/Documents/Development/GitHub/python-o365/O365/subscriptions.py", line 278, in delete_subscription
    response = self.con.delete(url, **request_kwargs)
  File "/Users/roger/Documents/Development/GitHub/python-o365/O365/connection.py", line 1146, in delete
    return self.oauth_request(url, "delete", **kwargs)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Documents/Development/GitHub/python-o365/O365/connection.py", line 1080, in oauth_request
    return self._internal_request(
    
  File "/Users/roger/Documents/Development/GitHub/python-o365/O365/connection.py", line 1023, in _internal_request
    raise HTTPError(
    ^^^^^^^^^^^
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b | Error Message: SubscriptionId Guid format is invalid or contained all zeros.
192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 304 -
192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 304 -
192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 304 -
192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 304 -
192.168.1.50 - - [30/Dec/2025 13:32:43] "GET /subscriptions/aaaaaaaa-032a-4b24-80af-bd1f88e9f7b/delete?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 304 -

I used the id from the subscription as shown in subscriptions/list. Any help would be appreciated.

@sdelgadoc
Copy link
Contributor Author

Hey @RogerSelwyn, thanks for digging in. You were able to create a subscription, which is the hardest part. However, I wasn't able to reproduce your issue. But, I might have an idea of what might be causing it.

The subscription ID you are using looks strange aaaaaaaa-032a-4b24-80af-bd1f88e9f7b. The subscription ID's start with 8 characters, followed by a dash. However, yours starts with 8 a's, which although not impossible, is very unlikely. I wonder if you are using the correct subscription ID. Below is the reply from the list subscriptions endpoint. Make make sure your are using the "id" and not the "creatorId", or something else in the delete endpoint.

Can you generate another subscription, run the list subscriptions, try to delete subscription, and let me know if you still get the same error?

[
    {
      "id": "0fc0d6db-0073-42e5-a186-853da75fb308",
      "resource": "Users",
      "applicationId": "24d3b144-21ae-4080-943f-7067b395b913",
      "changeType": "updated,deleted",
      "clientState": null,
      "notificationUrl": "https://webhookappexample.azurewebsites.net/api/notifications",
      "lifecycleNotificationUrl":"https://webhook.azurewebsites.net/api/send/lifecycleNotifications",
      "expirationDateTime": "2018-03-12T05:00:00Z",
      "creatorId": "8ee44408-0679-472c-bc2a-692812af3437",
      "latestSupportedTlsVersion": "v1_2",
      "encryptionCertificate": "",
      "encryptionCertificateId": "",
      "includeResourceData": false,
      "notificationContentType": "application/json"
    }
  ]

@RogerSelwyn
Copy link
Contributor

I have masked my id since I’m not sure if the id is sensitive. It didn’t start with 8 As in the generated id.

@RogerSelwyn
Copy link
Contributor

Looking at what I’ve posted, it looks like I’m one character short on the subscription id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants