From 3221bc82a621829284feae51e7fc737eb44e61be Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Tue, 17 Nov 2026 09:18:41 +1100 Subject: [PATCH] Ask for drafts by default in Api.get_drafts Substack's draft listing endpoint now answers 400 "Invalid value" for the filter parameter when none is sent, so get_drafts() failed unless the caller passed filter="draft" explicitly. Make that the default. Co-Authored-By: Claude --- CHANGELOG.md | 3 +++ substack/api.py | 6 ++++-- tests/substack/test_api.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d4a60..1bf9ccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ - Nested color and highlight spans override inherited styles of the same type without creating duplicate ProseMirror marks or changing sibling styles. Repeated style properties use the last nonempty declaration. +- `Api.get_drafts()` now asks for drafts by default. Substack rejects the + request with `400 Invalid value` when no filter is sent, so calling it + without arguments always failed. ### Development diff --git a/substack/api.py b/substack/api.py index 467347c..103048b 100644 --- a/substack/api.py +++ b/substack/api.py @@ -430,11 +430,13 @@ def get_posts(self) -> dict: return Api._handle_response(response=response) - def get_drafts(self, filter=None, offset=None, limit=None): + def get_drafts(self, filter="draft", offset=None, limit=None): """ + List the publication's drafts. Args: - filter: + filter: Which posts to list. Substack rejects the request when + this is missing. offset: limit: diff --git a/tests/substack/test_api.py b/tests/substack/test_api.py index f0e71c9..461cc84 100644 --- a/tests/substack/test_api.py +++ b/tests/substack/test_api.py @@ -143,6 +143,22 @@ def test_get_drafts_extracts_posts_from_response_envelope(self): self.assertEqual(api.get_drafts(), [{"id": 42}]) + def test_get_drafts_asks_for_drafts_by_default(self): + # Substack rejects the request with a 400 unless a filter is sent. + api = Api.__new__(Api) + api.publication_url = "https://writer.substack.com/api/v1" + api._session = Mock() + response = Mock(status_code=200) + response.json.return_value = {"posts": []} + api._session.get.return_value = response + + api.get_drafts(limit=5) + + api._session.get.assert_called_once_with( + "https://writer.substack.com/api/v1/drafts", + params={"filter": "draft", "offset": None, "limit": 5}, + ) + @pytest.mark.live @_e2e def test_get_posts(self):