# 4. Test and publish

:::lead
Send the parameters, the prices and the product to test, and publish them when the whole sales
package has been tested. Work from the bottom up: parameters first, then prices, then the
product.
:::

## Before you begin

Make sure that:

- You have the `id` and `versionId` of each parameter and fare table you created, and of your
  product.
- You have read
  [Publish order](/docs/partner-services/fare-data/versions-and-lifecycle#publish-order).

## 1. Send the parameters and prices to test

Send the version of each parameter you created to test, with the effective dates it should have. `propose` makes it
available in the staging environment. The example is valid from 1 January 2027 with no end date,
so `toDate` is left out:

`POST /v3/parameters/purchase-windows/{id}/{version}/propose`

```sh
curl --request POST \
  --url "https://api.entur.io/products/partner/v3/parameters/purchase-windows/EXA:PurchaseWindow:1b7d4c2a/EXA:Version:9e3f0a61/propose" \
  --header "Authorization: Bearer <ACCESS_TOKEN>" \
  --header "ET-Client-Name: example-fare-admin" \
  --header "content-type: application/json" \
  --data '{
    "validBetween": { "fromDate": "2027-01-01" },
    "note": "Ready for test"
  }'
```

The version now has status `PROPOSED`.

Send the fare table to test in the same way, with the same effective dates:

`POST /v3/fare-tables/{id}/{version}/propose`

## 2. Send the product to test

`POST /v3/supplement-products/{id}/{version}/propose`

```json
{
  "validBetween": { "fromDate": "2027-01-01" },
  "note": "Ready for test"
}
```

When you propose, the API only checks that the parameters exist. The full
[coverage rule](/docs/partner-services/fare-data/versions-and-lifecycle#coverage-rule) is
checked when you publish.

## 3. Check what is under test

Read the product back and check that its status is `PROPOSED` and that the content is right:

::endpoint[products-api/getSupplementProductVersion]

Travellers buy sales packages, not products. You test the purchase in the Entur app for staging
once the product is in a sales package that is under test. See
[5. Create a sales package](/guides/fare-data/5-sales-package).

If something is wrong, send the product back to `DRAFT`, fix it with `PUT`, and propose it
again:

`POST /v3/supplement-products/{id}/{version}/withdraw`

## 4. Publish

When the sales package has been tested, publish in the same order: the parameters first, then
the fare table, then the product. Publish the sales package last. `publish` makes the version available in the production environment.

`POST /v3/parameters/purchase-windows/{id}/{version}/publish`

`POST /v3/fare-tables/{id}/{version}/publish`

`POST /v3/supplement-products/{id}/{version}/publish`

```json
{
  "validBetween": { "fromDate": "2027-01-01" },
  "note": "Tested in staging"
}
```

Give the effective dates again when you publish. The dates you used for testing are not carried
over. `fromDate` can't be in the past.

## What happens if you publish in the wrong order

If you publish the product while a parameter it refers to is still `PROPOSED`, the API rejects
the request, because a published product needs published parameters:

```json
{
  "title": "Invalid parameter reference",
  "status": 400,
  "detail": "purchaseWindowRef 'EXA:PurchaseWindow:1b7d4c2a': Eligible parameter versions do not cover 2027-01-01 to open end for VERSIONED",
  "field": "purchaseWindowRef",
  "reference": "EXA:PurchaseWindow:1b7d4c2a"
}
```

Publish the parameter, and then publish the product again.

## Next steps

[5. Create a sales package](/guides/fare-data/5-sales-package)
