Promotions

Overview

What a promotion is, where it comes from and how to join one.

A promotion is a discount with a deadline on a Connection. You create your own and accept the campaign invitations the marketplace sends. Each listing takes part through an entry, with its own promotional price.

Where this fits in the journey: Grow and track.

Endpoints

MethodPathWhat it does
GET/v1/promotionsList promotions
POST/v1/promotionsCreate promotion
GET/v1/promotions/{promotionId}Get promotion
PATCH/v1/promotions/{promotionId}Update promotion
DELETE/v1/promotions/{promotionId}Cancel promotion
GET/v1/promotions/{promotionId}/listing-entriesList entries
PUT/v1/promotions/{promotionId}/listing-entriesReplace entries
GET/v1/listings/{listingId}/promotionsListing promotions
GET/v1/listings/{listingId}/promotion-eligibilitiesListing eligibilities
POST/v1/listings/{listingId}/promotionsCreate promotion for a listing

All of them need Authorization: Bearer mk_your_api_key. See Authentication.

Origin and type

  • origin: seller: created by you through the API.
  • origin: marketplace: a campaign invitation. You only join or leave, through the entries. Editing or cancelling returns 409.

type is discount, campaign, coupon, bundle, flash_sale or volume. A campaign starts only at the marketplace and arrives as an invitation.

What each marketplace lets you create is in declarations["promotions.creatableTypes"] of the Connection capabilities. A type outside the list returns 422 CAPABILITY_UNSUPPORTED, before anything is created. An empty list means the marketplace takes no promotion from the API. The operations are promotions.read (read) and promotions.manage (write).

Period and subsidy

A promotion has startsAt, endsAt and, on an invitation, joinDeadlineAt: the deadline to join. sellerShareBps is the share of the discount the seller pays, in bps (5000 is 50%); the marketplace pays the rest. null means the marketplace does not say.

Currency

Every promotion has a currency (an ISO 4217 code such as BRL). It applies to every amount in cents: the promotionalPriceInCents of the entries, priceRange and the *InCents of terms. In Create promotion you send the currency, and it must be the currency of the offer of each entry (400 with details.field: "currency" otherwise). In Create promotion for a listing the currency is the one of the offer, with no field in the body. On an invitation, it is the one the marketplace reports.

Lifecycle

statusMeaning
pendingcreated here, the marketplace has not answered yet
scheduledconfirmed, starts in the future
active / pausedrunning / paused
ended / cancelledfinished on schedule / you cancelled it
rejectedthe marketplace refused it; see statusReasons
unknowna state we do not know

ended, cancelled and rejected stay as history and take no more writes (409). While it is pending and its creation job (promotion.create) is queued or running, it takes none either: every write, DELETE included, returns 409 promotion_pending. Wait for the job.* webhook of that job. If the job failed and the promotion is still pending, waiting does not help: DELETE returns 204 and deletes the promotion, then create again with POST. If the marketplace refused it (rejected, see statusReasons), DELETE returns 409 promotion_closed: create another promotion. When the marketplace refuses the promotion, the entries you sent at creation become rejected too (marketplace_rejected in statusReasons), each with its own promotion.entry_updated. A write (PATCH, DELETE or PUT …/listing-entries) while another write job of the same promotion is queued or running returns 409 promotion_job_in_progress: wait for the job.* and send again.

Entries

Each entry links an offer line (bindingId) to the promotion, with promotionalPriceInCents or discountBps (one becomes the other from the regular price of the offer), stockLimit and purchaseLimit. The promotional price lives on the entry, not on the offer.

The entry status is candidate (invited, not joined), pending, active, paused, rejected, removed, ended or unknown.

unknown on joining: if the request to join for an entry fails without the marketplace refusing the line (a drop, a token or a failure of ours before the call), the job item fails and the entry becomes unknown, with promotion.entry_updated. It is not a refusal: we do not know whether the line got in. The call quota does not cause it: it only puts the job off, the job runs again and the entry stays pending. If the marketplace refuses the call (VALIDATION), the entry becomes rejected with marketplace_rejected in statusReasons. The entry is pending from the moment the PUT answers (an entry that already existed moves to pending with its promotion.entry_updated), and unknown or rejected are what a failed join turns it into. An unknown entry leaves with the promotion when you end it. unknown does not count as joined, so the same PUT of Replace entries tries the line again. If it had got in there, the sync fixes the status.

Join an invitation

  1. List the open invitations of the listing in eligibilities. Each item has the candidate entry with priceRange (minimum, maximum and suggested) and the promotion with its joinDeadlineAt.
  2. Send the bindingId of that entry, with a price inside the range, to Replace entries.
curl -X PUT "$BACKEND_URL/v1/promotions/$PROMOTION_ID/listing-entries" \
  -H "Authorization: Bearer mk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "entries": [{ "bindingId": "'$BINDING_ID'", "promotionalPriceInCents": 8990 }] }'

The answer is 202 with a promotion.entries_update job. The entry becomes pending right away (an existing one emits a promotion.entry_updated) and turns active when the marketplace accepts.

The PUT sends the whole set of joined lines. A joined line you leave out leaves the promotion; candidate, rejected, removed, unknown and ended lines left out do not change. A body that changes nothing creates a job with no items, which finishes at once.

Writes are jobs

Every write returns 202 with a job: promotion.create, promotion.update, promotion.end and promotion.entries_update. The job has one item per promotion (resourceType: promotion) or per entry (resourceType: promotion_listing_entry). The route only asks; the marketplace decides, and the result shows up on the promotion, on the entries and in the webhooks. On creation (promotion.create) and on an entry, a refusal becomes rejected and the job item fails. On PATCH, on DELETE (ending) and on removing a line, the refusal only fails the item: the promotion or the line stays as it was, still open. Cancelling a pending promotion the marketplace never created deletes it here and returns 204, with no job. If the creation job failed after the marketplace created it, cancelling ends it there (202, a promotion.end job).

Reads come from our database, kept fresh by sync.

Webhooks

You receive promotion.created (a new promotion, yours or an invitation), promotion.updated (any field of the promotion in the API changed, except externalPromotionId, lastSyncedAt and updatedAt) and promotion.entry_updated (an entry changed). No event is sent when nothing changed.

promotion.entry_updated with previousStatus: null means a line marketapi did not have yet: the marketplace listed it in a promotion marketapi already had, an invitation or your own (in an invitation, the entry is born candidate). The lines of a promotion new to marketapi do not emit this event: its promotion.created announces the promotion, and the lines are read through GET /v1/promotions/{promotionId}/listing-entries. unknown is a different case: it is the state of a failed join, and it never shows up as previousStatus: null.

The payload carries only ids, codes and dates: promotionId, connectionId, type, status, reasonCodes, startsAt, endsAt. It has no name and no terms (a coupon code, for example): fetch the promotion with Get promotion. The full list is in Receiving webhooks.

To renew your own promotion before it ends, see Promotion renewals.