SMM API Status Polling: Handle Partial Batch Responses
A batch status response can contain useful information and a failure at the same time. If four orders have valid results and one has an item error, treating the whole response as successful hides the error. Treating it as a total failure discards the valid observations. Match every result to the order ID requested and decide separately what can be updated.
This guide uses a five-ID offline fixture: two valid status objects, one item error, one missing ID and one unexpected shape. The original orders, amounts and timestamps are fictional. The purpose is to make a polling client's decisions inspectable without an API key or paid order.
Queue known order IDs, not create requests
The AlwaysCompleted API reference documents a multiple-order status action using comma-separated order IDs, with up to 100 IDs in a request. Keep a local queue keyed by the order IDs already received from successful creation or independently reconciled afterward. A status failure is not evidence that an order should be created again.
An order row should separate the latest attempted check from the latest successful observation. Useful local fields include last_attempt_at, last_good_at, next_check_at and a diagnostic classification. These are application design fields; they are not additional API response fields.
The distinction supports an honest customer message: “Last confirmed Pending at 10:00; the 10:05 check could not refresh this order.” Showing only “Pending, updated 10:05” would turn an unsuccessful check into apparent fresh evidence.
Partition requests without inventing a rate limit
Deduplicate the due IDs, sort them consistently and partition them within the documented maximum. A 101-ID queue becomes a batch of 100 and a batch of one. That maximum describes request size, not how frequently you may make requests.
Choose your polling schedule from operational needs and observed service behavior. A newly submitted order, an older unchanged order and a record needing manual investigation do not necessarily need the same schedule. Avoid allowing a permanently failing ID to occupy every worker cycle.
If a server returns HTTP 429, MDN explains that a Retry-After header may specify a wait. Respect an applicable response and use bounded scheduling when it is absent. This is general HTTP handling, not a claim that we observed a particular AlwaysCompleted limit or 429 response.
Validate the envelope, then each item
First confirm that the response is the expected JSON object. A top-level action error or an HTML page cannot be treated as a collection of successful order observations. Preserve the last good state and record that this attempt did not refresh it.
For a valid envelope, examine each requested ID. Do not depend on the order of members in a JSON object, and do not assign results by array position. Handle these cases independently:
- A validated status object updates the observation and its timestamp.
- An item error keeps the previous observation and records a diagnostic.
- An absent requested ID stays in the queue for investigation or another scheduled read.
- A malformed object keeps the previous observation rather than overwriting it with empty fields.
- An unrequested ID is flagged separately and does not create a new local order.
Validate fields before using them. A charge string containing NaN, for example, should not enter a financial ledger merely because a decimal parser recognizes it. An unfamiliar status string may be preserved as the API's reported value, but it must not acquire a terminal meaning from a guess.
Inspect the five-ID before-and-after result
Every row starts with a fictional Pending observation at 10:00 UTC. The next response arrives at 10:05.
| Order | Response member | Local decision |
|---|---|---|
| 910001 | Completed with valid fields | Replace the observation; timestamp 10:05 |
| 910002 | Partial with valid fields | Replace the observation; timestamp 10:05 |
| 910003 | Item error | Retain Pending from 10:00; mark the refresh unsuccessful |
| 910004 | Missing | Retain Pending from 10:00; diagnose the omission |
| 910005 | Unexpected array | Retain Pending from 10:00; diagnose the shape |
The response has two successful updates, not five. That conclusion remains true even if the HTTP request itself succeeded.
In the downloadable example, successful rows receive another check five minutes later and diagnostic rows ten minutes later. Those intervals are exercise settings, not a platform recommendation. Its stale flag means that the latest attempted refresh failed; a production dashboard may also apply a separate age threshold to successful observations.
Preserve timestamps through storage and restart
Write the accepted observations and diagnostic decisions durably before acknowledging the polling job. If multiple workers can check the same order, prevent an older response from overwriting a newer stored observation. A transaction, version check or ownership rule belongs in the storage design.
The supplied Python code deliberately stops at an in-memory merge. It does not implement database persistence, worker leases, crash recovery or out-of-order-write protection. These are important limits: a correct dictionary transformation is only one part of a reliable polling service.
On restart, load due known IDs from durable state. Do not reconstruct a list of orders to create from the fact that status information is stale. Submission recovery and status refresh are different jobs, even if both display a “needs review” indicator to the operator.
Give repeated failures an owner
A missing item can be retried as a read under a bounded policy. Repeated omissions deserve an investigation threshold rather than an endless loop. Check that the stored order ID is correct, the batch format matches the reference and the account context is the intended one.
An item error should not erase the previously known order or automatically resolve the customer's issue. Preserve the evidence needed by technical support: action, known order ID, attempt time, HTTP classification and a redacted diagnostic. Avoid copying API keys, full request bodies or personal destination URLs into routine logs.
For customer reporting, display the observed status and its age together. The campaign reporting worksheet can carry an explicit unresolved item instead of forcing every order into a completed outcome.
Run the offline example
- Five-ID merge and defensive checks
- Before state, mixed response and expected results
- Before-and-after table and queue review
Save the JSON and Python files together, then run python3 batch_status_merge.py. The runner checks the five required outcomes and additional cases for replay, malformed envelopes, unfamiliar status text, invalid money, chunking and duplicate IDs. It performs no API requests.
Before deploying a poller, compare the current API reference with your parser and confirm the durable queue behavior described in the developer guide. A useful poller improves knowledge about an existing order without turning missing knowledge into another purchase.