PATCH /listings/{code} or, if you work with your ids, with PUT /listings/ref/{ref}. Both send only what has changed and both protect you from overwriting a change made in the meantime in the portal.
JSON Merge Patch
The body of aPATCH follows the JSON Merge Patch rules (RFC 7386):
- a sent field replaces its value;
- a sent field with
nullis emptied; - a not sent field remains as it was.
features, heating_types, orientations) are completely replaced. To add an amenity, you send the complete list, including the new amenity.
After combining, the resulting listing goes through the same rules as an edit from the form. A PATCH cannot empty a mandatory field: {"street": null} receives 422 with required on /street.
What response do you receive
The body of the response is the listing, plus
warnings[] (see below). At 202, the listing in the response still has the public values: your change is visible after approval.
Versions: ETag and If-Match
A listing submitted via API remains editable from the portal: the agent can correct a price directly on housera.ro. To ensure that an automatic synchronization does not silently delete such a correction, each listing has a version.
- When you read the listing, you receive the version in the
ETagheader and in theetagfield. - When you edit, you send it back in the
If-Matchheader. - If the listing has changed in the meantime (an edit in the portal, another request), you receive
412 Precondition Failedand nothing is written.
412, you read the listing again (GET /account/listings/{code}), decide which version wins, and resubmit with the new ETag.
The version changes when the content of the listing changes, including an edit that is awaiting moderation. When someone edits the listing in the portal, you also receive the webhook listing.edited_in_portal, with the new etag.
PUT /listings/ref/{ref} applies just like a patch
On an id that Housera already knows, PUT /listings/ref/{ref} does not replace the whole listing, but behaves like a PATCH:
- the fields you send get updated;
- fields that you do not send retain their value, they are never emptied;
- an explicitly sent field with
nullis emptied; If-Matchis respected in the same way, with412on an old version.
Identical body: X-Housera-Unchanged
If you send to PUT /listings/ref/{ref} exactly the same body as the last successful write, Housera does not write anything and does not submit anything for moderation. You receive 200 with the current listing and header:
Warnings: warnings[]
Any successful response to a write (POST, PUT, PATCH) contains the list warnings[], with what you sent and was not taken:
A warning does not block the write, but tells you that your mapping is sending something unnecessary. The list of fields and amenities allowed for each type and transaction is in vocabulary.
Concurrency conflicts
If two writes arrive at the same time on the same listing, the second may receive409 listing_busy. Nothing was written: you retry after a second or two.