# Create a geo rule `POST /api/v1/geo-rules` ## Headers - `Idempotency-Key` (string, required) — A unique key per logical write. Replaying a request with the same key returns the first response byte for byte instead of applying the write twice. ## Request body Required. - `name` (string, required) — Unique per store, which makes it a stable handle a migration tool can re-run against. A duplicate is 409 rule_exists rather than a second rule. - `enabled` (boolean, required) — false leaves the rule stored and stops the storefront evaluating it. This is the REVERSIBLE form of removing a rule, and it is reachable on write_geo alone, unlike the DELETE. - `priority` (integer, required) — Evaluation order, LOWEST FIRST, and the first matching rule wins. Not unique and not a position in the list: the list is paged by creation time precisely because re-prioritising one rule would otherwise shift every rule after it across a page boundary. - `match_type` (country | ip_cidr, required) — Decides how match_values is read. - `match_values` (array of string, required) — Two-letter ISO 3166-1 alpha-2 country codes for a country rule, normalised to uppercase, or CIDR blocks for an ip_cidr one. At least one; an empty array is refused rather than stored as a rule that matches nothing. - `action` (switch_market | redirect_url | banner | popup | block, required) — switch_market needs target_region_id. redirect_url needs an absolute http(s) target_url. redirect_url and block require a paid plan and are refused 402 on a plan without it, rather than stored and silently ignored. - `target_region_id` (string | null) — The market a switch_market rule moves the shopper into. A region of this store, listed at /api/v1/regions; a region id from anywhere else is 400 invalid_region rather than 404. Null or omitted on every other action. - `target_url` (string | null) — Where a redirect_url rule sends the shopper. Absolute, http or https. - `target_locale` (string | null) — The language a switch_market rule also sets, like en or en-CA. Omit it to leave the shopper's language alone. - `redirect_status` (301 | 302) — Only meaningful on a redirect_url rule. Omit it for 302. Anything other than 301 or 302 is a 400 rather than a silently corrected redirect. - `display` (object) — The presentation document for the banner, popup or block surface: colours, position, dismissible, and the switch_market mode. It is sent and served as the stored document rather than as named fields, so a read is round-trippable through this replace; a client that dropped it would blank the merchant's styling and the banner would go plain with nothing to say why. Colours must be strict hex and position must be top or bottom, because both reach inline styles on the storefront. Omitted means {} and therefore the storefront's own defaults. ## Responses - `201` — Created - `400` — The request was refused before any state changed. `code` is one of: `invalid_body`, a write body this route will not take. `reason` partitions it and `field` names the key when one key is at fault. `invalid_query`, a query parameter, including limit and after. `invalid_text`, a NUL byte or bytes that are not valid UTF-8 anywhere in the path, the query or the body. Strip control characters before sending. `idempotency_key_required`, a write sent without the Idempotency-Key header. `invalid_request`, an Idempotency-Key longer than 255 bytes. Routes add their own codes for rules only they know. Switch with a default arm. - `401` — No credential, or one this API does not accept. `code` is always `unauthorized`. THE BODY IS DELIBERATELY UNINFORMATIVE. An expired key, a revoked key, a publishable key, a key belonging to another merchant and a key that never existed are all refused with the same bytes, so this response cannot be used to probe which keys exist. Check the key's state in the dashboard rather than inferring it here. Send the key as `Authorization: Bearer ` or as `X-API-Key: `. It is never accepted in a query string. - `403` — The key lacks the write_geo scope. `code` is `insufficient_scope` and the message names the scope to ask the merchant for. - `409` — The request is well formed and the store's current state refuses it. EVERY WRITE CAN ANSWER TWO OF THESE, whatever it does: `idempotency_key_reused`, this Idempotency-Key already served a different method, path or body. The key namespace is per store and not per endpoint, so a key built from a business id collides across routes; use a fresh key per logical write. `idempotency_key_in_progress`, an identical request is still running. Retry after a short delay; exactly one of the racing calls will have applied. `not_configured` means the merchant has not set something up yet, with `resource` naming what. The remaining codes are the per-route state rules named on the operation. - `413` — The request body exceeded the cap named in the message. `code` is `payload_too_large`. Nothing was read and nothing was recorded, so the same Idempotency-Key may be reused once the body is smaller. - `415` — The body was not declared as `application/json`. `code` is `unsupported_media_type`. This API reads ONE media type. The `+json` structured suffixes are refused too, because they name semantics (merge-patch in particular) this API does not implement, and reading such a body as plain JSON would be a silent misreading. A write that carries NO body needs no Content-Type at all. - `422` — An id INSIDE the request resolves to nothing on this store. `code` is `unprocessable_reference`, `resource` names the kind of thing that did not resolve and `field` names where it arrived, so the fix is mechanical. Distinct from 404, which is about the url, and from 400, which is about the bytes. The message stays generic about WHY the id did not resolve: an id owned by another merchant must read identically to one that never existed. - `429` — Too many requests. `code` is `rate_limited`. Two limits apply independently: one on the credential and the route family, one on the client address. The headers describe whichever has less left, so honouring Retry-After always clears the window that bound. - `default` — Any status this operation does not list, in the same envelope. A 5xx means the request may or may not have applied. Retry it with the SAME Idempotency-Key: that is the only way to find out without risking a duplicate, and it is what the key is for. A few 4xx conditions arrive here rather than as a listed status because they depend on the merchant's plan or on a module being wired: 402 when a quota or a plan limit is reached, and 503 when a capability the route needs is not configured on this deployment. Both carry a `code` naming which. ## Example ```bash curl --request POST \ --url 'https://api.mercemur.com/api/v1/geo-rules' \ --header 'Authorization: Bearer ' ```