Repository navigation
Match the SDK to the Siren API as it is served today - #4
Conversation
The reconciliation readers sent page and perPage, which Siren never reads,
and parsed only bare arrays, while Siren answers these lists with
{items, total, page, perPage, totalPages}. Every call returned no rows. The
readers now send number and offset, cap the page at 200, and read the list
body.
construct_event looked for type, data and deliveryId in the body. A plain
subscription's body is the payload alone, with the type in X-Siren-Event and
the event id in X-Siren-Delivery. construct_event now takes both headers and
also unwraps the versioned envelope a connected site's subscription gets.
Errors now read error.context when there is no error.data, so a failed field
check (a 400 from Siren) exposes its messages on BadRequestError.field_errors.
api_keys.create requires scopes, because Siren refuses a key without them
and issues event scopes only. Records read dateCreated, the name Siren uses.
The two management lists take number and offset. EventResult exposes the
outcome body and the queued 202. WebhookEventType gains the seven events in
Siren's catalog that it lacked. openapi.yaml and the README describe the same
behavior, including that API keys only reach the event routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The Node SDK reads opportunityId from the ingestion body when the response carries no X-Siren-OID header, and lets api_keys.create send expiresAt and propertyId, which Siren's CreateApiKey accepts. This keeps the two SDKs the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e043361e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| LineItem: | ||
| type: object | ||
| required: [name, quantity, amount] | ||
| required: [amount] |
There was a problem hiding this comment.
Allow sale line items without a name
The updated schema now correctly documents amount as the only required line-item field, but Events.sale() still routes every item through _normalize_line_item(), which treats both name and amount as required and reads item["name"]. Consequently, a server-valid and newly documented call such as items=[{"amount": 10}] raises ValueError locally instead of reaching Siren; update the normalizer to make name optional as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
_normalize_line_item now requires only amount and sends name and external_id when they are given, with a test for items=[{"amount": 10}] (4a7b59f).
| return ( | ||
| "version" in payload | ||
| and isinstance(payload.get("type"), str) | ||
| and isinstance(payload.get("data"), dict) |
There was a problem hiding this comment.
Avoid mistaking ordinary versioned payloads for envelopes
For a plain subscription whose event payload contains the common version/type/data shape (for example, a custom event payload), this predicate classifies the payload as a connected-site envelope. construct_event() then replaces the header event type with the payload's own type, unwraps only data, and drops the rest of the payload. Presence of any version key is not a sufficient discriminator; validate the connected-site envelope's additional required fields or otherwise distinguish its delivery format before unwrapping.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
A body is now read as an envelope only when its id equals the delivery_id and its type equals the event_type, which is how Siren builds every envelope, or when neither is passed. Any other delivery keeps its whole body and the header type, and new tests cover a custom payload shaped like {version, type, data} (ed7f74b).
| externalId: | ||
| type: string | ||
| description: Your order/transaction id; used to match refunds later. | ||
| description: Your order/transaction id; used to match refunds later. A number is accepted too. |
There was a problem hiding this comment.
Represent numeric sale external IDs in the schema
The new description says that externalId may be a number, but its schema remains type: string. OpenAPI validators and generated clients will therefore reject numeric IDs even though this revision explicitly documents them as accepted by Siren; express the field as a string-or-number union so the machine-readable contract matches the stated API behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
externalId is now typed [string, number] on the sale and refund schemas, and a line item takes a number for externalId and name, in all three SDK specs (e3d3001).
| def create( | ||
| self, *, label: str, scopes: Optional[Sequence[str]] = None | ||
| ) -> ApiKey: | ||
| def create(self, *, label: str, scopes: Sequence[str]) -> ApiKey: |
There was a problem hiding this comment.
Permit API-key creation without a label
The revised ApiKeyCreate contract makes only scopes required, but the SDK method still requires the keyword-only label argument and always sends it. When callers want to use the API's valid unlabeled-key form, Python raises TypeError before making the request. Make label optional and omit it from the payload when absent so this SDK surface matches the updated API contract.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
label is now an optional keyword and is left out of the request when not given, with a test for that case (4a7b59f).
Siren puts a 400's broken rules in error.context.failedValidations as a
list, one {field, message, type, context} entry per rule. PHPNomad's
ValidationMiddleware merges each field's failures into that list, and
Siren's SaveCollaboratorTrackingAlias builds the same shape by hand.
BadRequestError.field_errors looked for an object keyed by field, so it
returned an empty dict for every real validation failure. Its test
pinned the object shape Siren never sends.
field_errors now returns the list of entries, as BadRequestError's
fieldErrors does in the Node SDK, and the test uses Siren's shape.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A subscription made through POST /webhooks receives the event payload alone, and Siren names the event only in the X-Siren-Event header. The construct_event() call from 0.1.0, which passes no headers, turned every such delivery into an event with an empty type, which no handler matched and nothing reported. construct_event() now raises SignatureVerificationError when a bare payload comes without event_type, so an unchanged caller fails loudly and Siren retries the delivery. The versioned envelope still needs no headers. The CHANGELOG lists the changes that break 0.1.0 callers and names 0.2.0 as the next release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A connected site's subscription receives an envelope, but Siren sends it with the same X-Siren-Event and X-Siren-Delivery headers as an ordinary delivery. construct_event knew the envelope by a version key beside type and data, so a custom event's payload with those keys had its type replace the header's and lost everything outside data. Siren writes the delivery id into the envelope's id and the event type into its type. construct_event now reads a body as an envelope only when both match the event_type and delivery_id it was given, or when it was given neither. This is the rule the PHP and Node SDKs use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SaleEventFactory requires only amount on a line item, but the SDK raised ValueError for a line item without name. It now sends name and external_id when they are given. A sale's and a refund's external_id may be a number, which Siren stores as text. Siren's CreateApiKey reads label as optional. api_keys.create took it as a required keyword. It is now optional and left out of the request when not given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The spec applied the API key scheme to every route, so generated clients sent an API key to the webhook, API key and reconciliation routes, which answer 401 to one. It now defines dashboardSession and connectorToken beside apiKey and sets security on each operation. The event routes and the new GET /ping take an API key. The API key and webhook routes take a dashboard session only. The reconciliation routes take a dashboard session or a connected site's token. The PHP and Node specs match. externalId takes a string or a number in every schema, and a line item's name does too. The page size schemas drop maximum: 200, because Siren lowers a larger size to 200 rather than refusing it. The webhooks tag says how an envelope is told apart from a plain payload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Siren Cloud 3.6.259 gives API keys six new scopes. The ledger scopes open the conversion, transaction, obligation and payout reads, and the webhook scopes open webhook subscription management. Since 3.6.260 the manage scope also sends a test delivery. ApiKeyScope names the scopes, mirroring the PHP SDK, and the docstrings, README and openapi.yaml say which key each call takes. The key management routes stay session-only. Siren's new refusals get their own errors: ApiKeyNotAcceptedError for api_key_not_accepted, MissingScopeError with scope and any_of, and StoreKeyNotAllowedError for store_key_not_allowed. The reconciliation readers take property_id to narrow an organization-wide read to one store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dates the unreleased changelog as 0.2.0 and sets the version in pyproject.toml, _version.py (which the User-Agent reads) and the OpenAPI file, so the release tag matches what the SDK reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What changed
The SDK was checked call by call against Siren's
origin/main(fd24e0962, 2026-10-18). Five existing calls did not match what the API sends or accepts, and some of them never did. This PR fixes them, bringsopenapi.yamland the README in line, adds the API key scopes Siren Cloud shipped in 3.6.259 and 3.6.260 (Novatorius/siren#494 and #495), and prepares the 0.2.0 release.API keys read the ledger and manage webhooks. Siren Cloud 3.6.259 gives keys six new scopes, and 3.6.260 lets the manage scope send a test delivery.
siren.ApiKeyScopeenum mirrors the PHP SDK's class:ALL_EVENTS,FULL_ACCESS,SALE,REFUND,SITE_VISITED,LEDGER_CONVERSIONS_READ,LEDGER_TRANSACTIONS_READ,LEDGER_OBLIGATIONS_READ,LEDGER_PAYOUTS_READ,WEBHOOK_SUBSCRIPTIONS_READandWEBHOOK_SUBSCRIPTIONS_MANAGE.siren.LEDGER_READ_SCOPESandsiren.event_scope(slug)sit beside it.api_keys.createtakes members or strings.webhooks.subscriptionswork with a key that holds the matching scope, and the README, docstrings and spec say so.api_keysstays session-only.ApiKeyNotAcceptedError(401api_key_not_accepted, subclassesAuthenticationError),MissingScopeError(403missing_scope, withscopeandany_of) andStoreKeyNotAllowedError(403store_key_not_allowed, withproperty_id), both subclassingPermissionError.siren.ErrorCodeholds the three codes.property_id, sent aspropertyId, to narrow an organization-wide ledger read to one store.openapi.yamlputs the ledger and webhook operations on theapiKeyscheme beside the session scheme, with the scopes each one needs, adds thepropertyIdandX-Siren-Propertyparameters, lists the new error codes, and addsPOST /webhooks/{id}/teston theapiKeyscheme withwebhook-subscriptions:manage. It passesopenapi-spec-validator.Release 0.2.0. The last commit dates the changelog as
## [0.2.0] - 2026-10-19under a fresh emptyUnreleased, and sets 0.2.0 inpyproject.toml,src/siren/_version.py(which the User-Agent reads) andopenapi.yaml.test_versionnow expects 0.2.0. The changelog links usevtags, so tag itv0.2.0.Reconciliation readers returned no rows.
conversions,transactions,obligationsandpayoutssentpageandperPage. Siren pages withnumberandoffset(PageSizeMiddleware) and ignores the others. Siren also answers these lists with{items, total, page, perPage, totalPages}(ListResponseWrapperInterceptor), and the SDK only read bare arrays. The readers now turnpageandper_pageintonumberandoffset, cap the page at 200, and read the list body.ListPagegainstotal_pages.construct_eventparsed real deliveries as empty. It readtype,dataanddeliveryIdfrom the body. Siren'sWebhookDeliveryServicesends a plain subscription the payload alone, with the type inX-Siren-Eventand the event id inX-Siren-Delivery.construct_eventnow takesevent_typeanddelivery_idfrom those headers. It also unwraps the versioned envelope a connected site's subscription gets. The envelope check looks forversion, becausecurrency.created's payload has atypekey of its own.Error details were always empty. Siren's REST layer sends
{"error": {"message", "code"?, "context"}}, and a failed field check is a 400 withcontext.failedValidations. The SDK only readerror.data. It now falls back tocontext, takescontext.typeas the code when there is no code, and exposes the messages onBadRequestError.field_errors.api_keys.createwithout scopes always failed. Siren answers 400 "At least one scope is required."scopesis now required, and the docstring names the scopes Siren accepts.Field names.
ApiKeyandWebhookSubscriptionreadcreatedAt, but Siren sendsdateCreated. Both now readdateCreatedand gainproperty_id.ApiKeyalso gainsrevoked_at.api_keys.listandwebhooks.subscriptions.listtakenumberandoffset, because Siren returns at most 200 rows a request and an org can hold 250 keys.Two additions follow API changes from October.
EventResultnow carrieshttp_status,body,statusandqueued. Siren answers a sale and a site visit with what came of them, and answers202withstatus: queuedwhile an org's processing is paused. When there is noX-Siren-OIDheader,opportunity_idcomes from the body'sopportunityId, as the Node SDK does.api_keys.createalso takesexpires_atandproperty_id, which Siren accepts.WebhookEventTypegains the seven events in Siren'sGET /webhooks/eventscatalog that it lacked:collaborator.updated,collaborator.deactivated,program.created,credit.issued,credit.redeemed,currency.createdandcurrency.deleted.Tests changed on purpose
Four existing tests encoded behavior Siren does not have, so they were rewritten with comments that name the Siren code they follow. They covered
page/perPageon the wire, bare-array list bodies, a{type, data, deliveryId}delivery body, and creating a key with no scopes. The event-type count tests now match Siren's catalog. New tests cover each fix and the new scopes.pytestpasses 119 tests.Related
The PHP SDK fixes the same webhook parsing and ingestion body in Novatorius/siren-php#8, and the Node SDK in Novatorius/siren-node#6. The shapes, scope names and error classes here match both, so the three SDKs stay the same.
🤖 Generated with Claude Code