Skip to main content

Publish and fetch pacts

Apiome speaks the Pact Broker's API for publishing and reading pacts. The pact-broker CLI, the pact CLI and the Pact libraries publish to it without changes: give them your workspace's broker base URL and an API key as the token.

This page covers publication and retrieval. A provider's verifier fetches the pacts it must verify with consumer-version selectors and publishes its results. Deploy jobs record where each version runs and ask whether a version can be deployed. To publish from the app instead of a build, use the Publish page — where you can also write a pact by hand; to see how a pact fares against several provider versions first, check it before publishing.

Before you start​

You need two things:

  1. The broker base URL. It is your API address followed by /v1/tenants/<workspace>/pact-broker — for the workspace acme, https://api.apiome.dev/v1/tenants/acme/pact-broker. If your operator set up a broker host for workspaces, the shorter https://acme.<broker host> is the same thing (see The broker host alias).
  2. An API key from a member who holds Pacts → Create — the built-in Editor role does. Create one on API keys — the Pact: consumer + deploy preset is enough. Pact tooling sends it as a bearer token or as the password of basic auth, and Apiome accepts both on every route under /pact-broker (see Pact keys and scopes).

You do not need to register the applications first. The first publication that names a consumer or a provider registers it as a pacticipant.

Publish from CI​

Run your consumer's Pact tests, then publish the pact files they wrote:

pact-broker publish ./pacts \
--consumer-app-version "$GIT_COMMIT" \
--branch "$GIT_BRANCH" \
--build-url "$CI_BUILD_URL" \
--broker-base-url https://api.apiome.dev/v1/tenants/acme/pact-broker \
--broker-token "$APIOME_API_KEY"

The CLI also reads PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN from the environment. With the newer pact CLI the command is pact broker publish with the same options.

It prints what Apiome did:

Created Billing Service version 2f4c1a9 with branch main
Pact successfully published for Billing Service version 2f4c1a9 and provider Ledger API.
View the published pact at https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/provider/ledger-api/consumer/billing-service/version/2f4c1a9

From pact-js, publishPacts takes the same values:

await publishPacts({
pactFilesOrDirs: ['./pacts'],
pactBroker: 'https://api.apiome.dev/v1/tenants/acme/pact-broker',
pactBrokerToken: process.env.APIOME_API_KEY,
consumerVersion: process.env.GIT_COMMIT,
branch: process.env.GIT_BRANCH,
});

Use the commit SHA as the consumer version. A version's pact is fixed once published (see What happens when you publish), so every build needs its own version number.

What happens when you publish​

One publish request carries one consumer version and its pacts, one per provider.

  • Applications are registered on first use. Billing Service becomes the pacticipant billing-service. A name that already has a pacticipant reuses it.
  • The consumer version is recorded with its branch, tags and build URL, following the registry's rules: a version never changes, and a branch head only moves forward.
  • The pact is stored as published. Pact specification 1.x to 4.x is accepted, including message pacts. No field is dropped or rewritten.
  • Identical pacts are stored once. Each distinct pact between a consumer and a provider is a pact version, named by the SHA-256 of its content. When ten builds publish the same pact, there are ten consumer versions and one pact version — one thing for the provider to verify.
  • All or nothing. If one pact of the request is refused, nothing of the request is stored.
  • Publishing again is safe. The same pact for the same consumer version changes nothing.
  • A different pact for the same consumer version is refused with 409 pact-content-conflict. Publish it under a new version number.
  • The consumer's declared surface is refreshed. A pact you publish also updates the consumer contract in the provider's project — see below.

One consumer model​

A consumer pacticipant and a consumer of a project are one thing. When a new pact is published for a provider that is bound to a project, Apiome resolves its interactions against that project's latest version and stores the result as the consumer's next contract revision (revision N + 1). The consumer is registered in the project under the pacticipant's handle the first time, so a CI job publishing for a new service works on its first run.

  • Nothing is dropped. An interaction that names a retired endpoint, a status the specification does not declare or a removed field stays on the revision as unresolved, with a reason code.
  • Unbound providers are reported. If the provider is not bound to a project there is nothing to resolve against, so the publish succeeds and the response says provider-not-bound-to-project. Bind it by setting the pacticipant's project (PATCH …/pacticipants/<provider>), then publish again.
  • Re-runs are quiet. The same pact against the same project version stores no new revision.
  • A publish never fails because of it. If the refresh cannot run, the pact is still published and the response reports error; publish again to retry.

The bulk publish response adds consumerContracts — one entry per pact with status (refreshed, unchanged, skipped or error), revision, resolvedCount, unresolvedCount and, when not refreshed, reasonCode and reason — and the same lines in notices, which the pact-broker CLI prints.

Because the consumer is the same, apiome diff --consumers and the diff-action name the pacticipant and the pact (consumer version and pact hash) behind each broker-backed consumer in their Consumer impact section.

What makes two pacts the same​

The pact version is computed from the document's interactions, its messages and the Pact specification version it declares. Key order does not matter; the order of interactions does.

The metadata block is not part of it. Pact libraries write their own name and version there, so upgrading the library does not turn an unchanged pact into a new one.

Publish from the UI​

The Publish a consumer pact page does what apiome pact publish does, from the browser. Open Contracts and click “Publish a pact” (or go to /ade/dashboard/pacts/publish).

The Publish a consumer pact page: The pact with Upload selected and a table of three files — Orders UI to Billing Service (Pact v3, 6 interactions), Orders UI to Orders API (Pact v4, 11 interactions) and ledger.json marked Not a pact: missing consumer — then Whose version this is with the consumer version, branch and tags, and The same, from anywhere beside them.The Publish a consumer pact page: The pact with Upload selected and a table of three files — Orders UI to Billing Service (Pact v3, 6 interactions), Orders UI to Orders API (Pact v4, 11 interactions) and ledger.json marked Not a pact: missing consumer — then Whose version this is with the consumer version, branch and tags, and The same, from anywhere beside them.
Route/ade/dashboard/pacts/publish

1. Bring the pact in​

Choose one of the tabs under The pact:

TabWhat it does
UploadDrop pact files or a whole pacts/ folder on the box, or click “Browse files” or “Browse a folder”. Each file gets a row: its consumer → provider, its Pact specification, its kinds of interaction (HTTP, Message, GraphQL, gRPC) and how many interactions it carries. Several providers and several consumers at once are fine.
PastePaste a Pact document into Pact JSON, or click “Paste from clipboard”. The detected specification is shown beside the button.
Derive from a projectPublish a consumer's declared surface as its pact, as apiome pact publish-consumer-contract does. Pick the Project and the Consumer; optionally a Revision (the current one otherwise) and the Provider pacticipant. Only a consumer declared with the picker can be derived — one imported from a Pact file says so in the list.
Write interactionsWrite the pact by hand in the interaction editor — for a team with no Pact tests yet. See Write interactions.
Record from a mockNo pact file and no Pact library? Click “Generate a pact from a mock” to open the page that records your consumer's calls to a hosted mock and writes the pact from them. It publishes from there, so nothing typed on this page is carried over. See Pact from a mock.

A file that is not a pact is marked in red with the reason — for example Not a pact: missing consumer, Not a .json file, or a second file for the same consumer and provider. The other rows still publish. Remove a row with its × button.

Write interactions​

No Pact tests yet? Write what the consumer sends and the answer it needs, and Apiome writes the Pact v4 document. It is checked and published like an uploaded file.

The Write interactions tab: Consumer Orders UI and Provider Billing Service, a line saying paths are checked against revision 2.7.0, the list of interactions on the left — GET get invoice 42, POST create an invoice, and GET list credit notes flagged as not in the spec — and on the right the selected interaction with its provider state an invoice exists (id = 42), the request GET /invoices/42 matching GET /invoices/{id} in revision 2.7.0, and Fill from the spec beside Response.The Write interactions tab: Consumer Orders UI and Provider Billing Service, a line saying paths are checked against revision 2.7.0, the list of interactions on the left — GET get invoice 42, POST create an invoice, and GET list credit notes flagged as not in the spec — and on the right the selected interaction with its provider state an invoice exists (id = 42), the request GET /invoices/42 matching GET /invoices/{id} in revision 2.7.0, and Fill from the spec beside Response.
Route/ade/dashboard/pacts/publish
  1. Click the “Write interactions” tab and type the Consumer (Orders UI) and the Provider (Billing Service). When you leave the provider field, Apiome reads that provider's spec — the latest revision of the project its pacticipant is linked to — with its registered provider states and its mock's scenarios. The line under the fields says which revision paths are checked against, or why none is (not a pacticipant yet, not linked to a project). Click “Read it again” after the spec changes.

  2. Choose a kind — HTTP, Message, GraphQL or gRPC — and click + beside Interactions. The list holds every kind; press ↑ and ↓ (or Home and End) to move through it.

  3. Fill in the interaction on the right:

    FieldWhat to enter
    DescriptionWhat the call is for: get invoice 42. Two interactions with the same description and provider states are refused — a verifier could not tell them apart.
    Provider stateClick “+ Provider state”, then type or pick what must be true first: an invoice exists. Suggestions come from the provider's state catalogue and its mock's scenarios; a catalogue state fills its parameters in. Type parameters as id = 42, currency = EUR — numbers, true and quoted "text" are read as JSON.
    RequestThe Method and the Path, such as /invoices/42. Under Headers, query and body, click “+ Header”, “+ Query parameter”, or type a Request body.
    ResponseThe Status, the Headers and the Response body.
    Fields the consumer relies onOne row per field with its matcher chip — $.id integer, $.currency regex ^[A-Z]{3}$, $.lines min items 1. Click “+ Field the consumer needs”, type the Field path, an Example value and choose the Matcher, then click “Add field”: the value goes into the body and the rule onto the field.

    A Message has Contents, Metadata and its fields. A GraphQL interaction is a POST of its Operation, Variables and Operation name to the path (/graphql). A gRPC call names its Service and method (billing.Invoices/GetInvoice) with a Request message and a Reply, written as JSON — the editor does not compile the .proto, so Apiome's hosted verifier reports descriptors missing for these until a protobuf-plugin test publishes the same calls. Publishing and checking still work.

  4. Check the path. Under the path, Matches GET /invoices/{id} in revision 2.7.0 means the provider's spec has the operation. Click “Fill from the spec” to take its response: the status, the content type, the example body and a matcher for every field. An example the spec does not give is generated from its schema and says review the values. A path the spec does not have reads GET /credit-notes is not in the spec and is marked in the list — it is flagged, not blocked: the pact still publishes, and the check reports it.

While something stops an interaction from being written — no description, a body that is not JSON, a path without its leading / — the interaction lists what to fix, the list marks it, and the row under the editor reads Not ready to publish. Nothing is sent until it is fixed.

The row under the editor is the written pact: its pair, Pact v4, its kinds and how many interactions it holds. Click “Download the pact” to save it — commit it under pacts/ and the command beside publishes it from CI.

To change a pact you already have, paste it on the Paste tab and click “Edit in Write interactions”. Anything the editor does not write — generators, header matching rules, pending, a second gRPC reply — is listed above the editor with the reason, so nothing is lost without you knowing.

2. Say whose version it is​

FieldWhat to enterapiome pact publish flag
ConsumerShown, not typed: each pact names its consumer. Several consumers are published one request each.—
Consumer versionA version that changes with every build, such as a commit SHA. Required.--consumer-app-version
BranchThe branch the build came from. Click “Fill from the linked repository” to use the consumer pacticipant's main branch.--branch, --auto-detect-version-properties
TagsOptional. Separate them with commas or spaces.--tag
More options → Build URLThe CI build's http or https address.--build-url
More options → Also tag with the branch namePuts the branch on the version as a tag too. Needs a branch.--tag-with-git-branch
More options → Merge with the pact already publishedApiome stores a version's pact as published and does not merge interactions, so turning this on stops the publish with that reason — as --merge does in the CLI.--merge

3. Check it before it counts​

Compare each pact with the provider versions it will meet, before anything is saved — see Check before publishing for what each choice means.

  1. Under Compare with, click a chip to switch it on or off. Provider’s main and the production environment start switched on; there is a chip for every environment of the workspace and one for Draft · latest. Click “+ Another version” and type 2.7.0, deployed:staging or draft:2.8.0-rc1 for anything else, then click “Add”. At most ten.
  2. Click “Compare now” (or “Check only” in the header, which also runs the check below).

The aside shows one card per pact — Orders UI → Billing Service — with one pill per provider version, such as main · 2.7.0 4/6 (four of six interactions match) and production · 2.6.1 6/6. Each interaction is marked:

MarkMeans
MatchThe provider's contract satisfies it.
DiffersThe contract contradicts it; the line under it says how, for example Needs currency in the 201 body.
Not in specThe contract declares no such operation. The provider may serve it undocumented.

What needs attention comes first; click “Show all” for the rest. Click “See the difference” to open what the pact needs beside what the spec declares, every finding, and — when the provider's contract was rendered from an Apiome project — “Open <project> <version>”, the project's version history. A provider version that could not be found is listed under the pills with the reason, and a provider with nothing to compare with reads Billing Service has no contract or deployed version yet. Publish anyway — the verdict appears when the provider shows up. Click “Re-check” to compare one pact again.

The Publish page after a check: Check it before it counts with Provider's main and Deployed to production switched on, and in the aside Orders UI to Billing Service with the pills main 2.7.0 4 of 6 and production 2.6.1 6 of 6 — POST /invoices marked Differs, GET /invoices/{id}/pdf Not in spec, and the matching interactions below.The Publish page after a check: Check it before it counts with Provider's main and Deployed to production switched on, and in the aside Orders UI to Billing Service with the pills main 2.7.0 4 of 6 and production 2.6.1 6 of 6 — POST /invoices marked Differs, GET /invoices/{id}/pdf Not in spec, and the matching interactions below.
Route/ade/dashboard/pacts/publish

A difference does not stop you from publishing: the pact records what the consumer needs, and the difference becomes the failing verdict the provider sees. The same check, from anywhere, under the chips, is the check as apiome pact check and its REST request.

4. Publish​

  • Click “Check only” to see what publishing would do, without writing anything. Besides the comparison above, each row says Nothing is published for 3.4.0 yet: this pact will be new, Unchanged since 8d2f1c0: its verification results still apply, or 3.4.0 already has a different pact. Use a new version — a different pact for a version that already has one is refused. Without a consumer version only the comparison runs.
  • Click “Publish pact”. The result dialog lists each pact: new content, pending for the provider until they pass it once; unchanged, so its verification results still apply; or changed. It also lists what was not sent and why, whether contract webhooks were notified (see Webhooks), and how many bi-directional comparisons ran. A derived pact also lists its findings — values invented or left out — and “Download the published pact”. Click “Can I deploy?” to go on, or “Publish another” to start over.

If REST refuses one pact of a request, that row is marked with REST's reason and the rest are sent again; nothing is dropped silently.

The same, from anywhere, beside the form, is the command for what the form holds — apiome pact publish pacts/ (or publish-consumer-contract for a derive), the Pact CLI, the GitHub Action step and the REST request — and lists anything the command cannot carry. See the CLI.

Publishing needs Pacts → Create. A role without it sees why and the command block only, so the pact can still be published from a build with an API key.

From the Export page​

Review and publish on the Export page brings a pact derived from a project here. With every operation ticked and the current revision, the page opens on Derive from a project with the project and consumer filled in; a pact with some operations left out, or from an older revision, arrives on Paste exactly as it was previewed. Say whose version it is, check it and publish as usual.

From the Import dialog​

You can also publish a pact as you import it. On a project's Consumers screen, click “Import Pact file”, choose or paste the pact, and tick “Also publish to the Pact Broker”. Fill in:

FieldWhat to enter
ProviderThe provider the pact is with. It starts as the project's handle.
Consumer versionThe consumer's application version, such as a commit SHA. Required.
Branch, Tags, Build URLOptional. Separate tags with commas or spaces. The build URL is an http or https address.

The consumer is the one you opened the dialog from, the Consumer handle you typed, or the name the pact document declares.

Click “Import”. Apiome stores the pact as a consumer contract first, then publishes it. The dialog stays open and shows both results: the revision stored, and the broker's notices. If the broker refuses the pact — for instance, a different pact for a consumer version that already has one — the dialog says so beside the stored revision; the import is not undone. Publishing needs Pacts → Create. Leave the box unticked to import to the registry only.

For several files, a check first, or tag-with-branch, click “open the Publish page” in the dialog: the page opens with the version, branch, tags, build URL and the pact already filled in.

Check before publishing​

A pact usually fails only after it is published, and then only against the one provider version a verifier ran. A check compares an unpublished pact with several provider versions at once — today's production and tomorrow's main — and stores nothing.

Each version is named by a selector:

SelectorCompares with
mainThe newest version on the provider's main branch that published a provider contract.
deployed:<environment>Every version with a provider contract that is deployed to, or released in, that environment.
version:<number>That provider version.
draft:<revision>A revision — a label, a revision id or latest — of the Apiome project the provider pacticipant is bound to, as it stands now. Needs Versions → View as well.

A version two selectors name is compared once. The answer for a version is the verdict a publish would record against it: the same comparison and the same comparison rules, including the self-verification policy — a provider contract without passing evidence reads unverified, and so does every draft, which has no evidence yet. A selector that names nothing — no main branch, nothing deployed there, an unknown version, a provider not bound to a project — is listed with the reason, never ignored.

From the CLI, with the same PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN as apiome pact publish:

apiome pact check pacts/ --against main --against deployed:production
Orders UI → Billing Service (pacts/orders-ui-billing-service.json)
Provider version | Selected by | Verdict | Match | Differs | Not in spec
-----------------|---------------------|---------|-------|---------|------------
2.7.0 | main | fail | 4 | 1 | 1
2.6.1 | deployed:production | pass | 6 | 0 | 0
2.7.0: POST /invoices — 201 differs: response.body.unknown-property: …
2.7.0: GET /invoices/{id}/pdf — 200 not in spec: request.operation.unknown: …
1 of 1 pacts would not pass against every provider version checked.
Nothing was published.

It exits 0 only when every pact passes against every version and every selector named one, and 1 otherwise, as pact-broker does — so it can gate a pull request before the pact is published. --output json prints the whole answer.

Over REST, send one pact per request:

curl -X POST https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/check \
-H "Authorization: Bearer $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"pact": '"$(cat pacts/orders-ui-billing-service.json)"', "against": ["main", "deployed:production"]}'

The answer has summary (versions, passed, failed, unresolved, skipped, success), one entry per version in results — providerVersion, selectors, reasons, verdict, success, counts and interactions, each with outcome (match, differs, not-in-spec) and, when it does not match, expected and declared (at most 8 KB each) — and unresolved and skipped. A check needs Pacts → View, takes 1 to 10 selectors and compares at most 20 versions; past that they are listed in skipped. An unknown field or selector is 422 pact-check-invalid with a pointer. Checks are budgeted per workspace (APIOME_PACT_CHECK_RATE_LIMIT_PER_MINUTE, default 60).

Publish one pact with curl​

To publish a single document without the CLI, PUT it:

curl -X PUT \
"https://api.apiome.dev/v1/tenants/acme/pact-broker/pacts/provider/ledger-api/consumer/billing-service/version/2f4c1a9" \
-H "Authorization: Bearer $APIOME_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @pacts/billing-service-ledger-api.json
  • 201 — this consumer version had no pact for the provider.
  • 200 — it had published the same pact before. Nothing changed.
  • 409 — it had published a different one.

The provider and consumer in the URL can be handles or names (Ledger%20API). If the document names its consumer and provider, they must match the URL. This request records no branch, tag or build URL; use the CLI, or POST …/pact-broker/contracts/publish, to send those.

Fetch a pact​

To readRequest
The pact one consumer version publishedGET …/pact-broker/pacts/provider/ledger-api/consumer/billing-service/version/2f4c1a9
The latest pact between the twoGET …/pact-broker/pacts/provider/ledger-api/consumer/billing-service/latest
The latest from a tag or a branchGET …/consumer/billing-service/latest/prod, GET …/consumer/billing-service/branch/main/latest — see Latest pacts without selectors
A pact by its pact versionGET …/pact-broker/pacts/provider/ledger-api/consumer/billing-service/pact-version/<sha>
The links to all of the aboveGET …/pact-broker

Latest means the consumer version that was recorded last, not the highest version number.

The answer is the pact document as published, with two additions: createdAt and _links. To save a pact as a file from the app — exactly as published, without those two — or every pact for a provider as a zip, use A pact file on the Export page (Export on a pact's page opens it on that pact).

LinkLeads to
selfThis pact, by consumer version.
pb:pact-versionThe pact by its content. Its name is the SHA-256. Every consumer version that published the same pact has the same link.
pb:latest-pact-versionThe latest pact between this consumer and provider.
pb:publish-verification-resultsWhere a verifier posts its result for this pact. See Publish verification results.
pb:latest-verification-resultsThe latest result published for this pact version.
pb:latest-tagged-pact-versionA template: the latest pact between them from versions with a tag ({tag}).
pb:consumer, pb:providerThe two pacticipants.
pb:consumer-versionThe consumer version, with its branches and tags.

When a pact is refused​

Every refusal carries a stable code in detail. When the problem is in one place, pointer is its JSON Pointer.

{
"detail": {
"code": "pact-invalid",
"message": "/interactions/2/request/method: the request method must be a non-empty string",
"pointer": "/interactions/2/request/method"
}
}
StatusCodeWhat to do
422pact-invalidThe document is not a pact. pointer names the place in the pact file: fix it there. A pointer of "" is the whole document — it is not JSON, or it has no interactions or messages array.
422pact-publish-invalidThe publish request is malformed. pointer names the field in the request — a missing version number, a contract for a different consumer, two contracts for one provider.
422pact-publish-unsupportedThe request asks for something not available: merging pacts (--merge), or a contract that is not a Pact JSON document.
409pact-content-conflictThis consumer version already has a different pact for the provider. Publish under a new version number.
413pact-too-largeThe pact is over the size limit (10 MiB unless your operator changed it).
429pact-publish-rate-limitedThe workspace is over its publish budget (120 a minute unless changed). Retry after the seconds in Retry-After.
404pact-not-found, pacticipant-not-foundNo such pact, or no such application in this workspace.
401 / 403—The token is not a valid API key for this workspace, or its member lacks Pacts permission.

Who can do what​

ActionNeedsViewerEditorAdminOwner
Read pacts and the indexpacts:view✓✓✓✓
Publish pactspacts:create—✓✓✓
Check a pact before publishingpacts:view (a draft: selector also versions:view)✓✓✓✓

A restricted API key (one with scopes) cannot use these routes yet; use a full-access key from a member with the Editor role.

The broker host alias​

Operators can give every workspace a broker address of its own, so the base URL is a bare host:

  1. Point a wildcard DNS record and TLS certificate for *.pact.example.com at the API.
  2. Set APIOME_PACT_BROKER_HOST_SUFFIX=pact.example.com on the REST service.

https://acme.pact.example.com/… is then served exactly as https://<api>/v1/tenants/acme/pact-broker/…, and the links in every answer use the host the client called. Only the Pact Broker routes are reachable on that host. The API key must still belong to the workspace the host names.

Settings for operators​

VariableDefaultWhat it does
APIOME_PACT_MAX_BYTES10485760Largest pact document accepted. A publish request may be twice this, because its pacts are base64-encoded.
APIOME_PACT_PUBLISH_RATE_LIMIT_PER_MINUTE120Publish requests per workspace per rate-limit window.
APIOME_PACT_CHECK_RATE_LIMIT_PER_MINUTE60Checks before publishing per workspace per rate-limit window.
APIOME_PACT_ALLOW_CONTRACT_MODIFICATIONfalsetrue replaces a consumer version's pact instead of answering 409. Only for teams whose version numbers are not unique per build: a provider may already have verified the pact that is replaced.
APIOME_PACT_BROKER_HOST_SUFFIXemptyTurns on the broker host alias.
APIOME_API_PUBLIC_URLemptyThe public address of the API. Set it when the service runs behind a proxy, so links in answers use the public address.