# 1. Create rules and parameters

:::lead
A product's rules live in separate parameters that the product refers to. Create them first,
because the product can only be published when its parameters are published.
:::

## Before you begin

Make sure that:

- You have a client and can get an access token. See [Authentication](/docs/authentication).

## What rules and parameters are

Rules and parameters decide when, where, for whom and on which conditions a product can be
bought and used. For example, one parameter can say how long before departure the product can
be bought, and another how long it is valid after purchase.

Each type of rule is its own element with its own endpoints in the
[Product parameters API](/apis/product-parameters-api). New types are added over time. The API
reference lists the types you can use today.

Rules and parameters are shared. One parameter can be used by many products, and many products
can use the same parameter. Before you create a new one, check whether you or Entur already have
one that fits.

## Why parameters come first

A product refers to its parameters by NeTEx id. Before a product can be published, its
parameters must be published for the whole time the product is valid. This is the
[coverage rule](/docs/partner-services/fare-data/versions-and-lifecycle#coverage-rule).

So the order is always the same, whatever the rule:

1. Find a parameter that fits, or create a new one.
2. Note its `id`, so the product can refer to it.
3. Send it to test and publish it before the product. See
   [4. Test and publish](/guides/fare-data/4-test-and-publish).

## Example: create a purchase window

A purchase window (`PurchaseWindow`) decides when a product can be bought. Every type of
parameter is created the same way: a `POST` with the content, which returns the new element.

The example allows purchase up to 90 days before, and at least one hour before, the product is
used:

::endpoint[product-parameters-api/createPurchaseWindow]

```sh
curl --request POST \
  --url "https://api.entur.io/products/partner/v3/parameters/purchase-windows" \
  --header "Authorization: Bearer <ACCESS_TOKEN>" \
  --header "ET-Client-Name: example-fare-admin" \
  --header "content-type: application/json" \
  --data '{
    "names": [
      { "lang": "nb-NO", "value": "Inntil 90 dager før" },
      { "lang": "en-GB", "value": "Up to 90 days before" }
    ],
    "purchaseWhen": "ADVANCE_AND_DAY_OF_TRAVEL",
    "minimumPeriodBeforeDeparture": "PT1H",
    "maximumPeriodBeforeDeparture": "P90D"
  }'
```

Leave out `ownerOrganisationId`. The parameter then belongs to the organisation in your token.

The response contains the new element:

```json
{
  "id": "EXA:PurchaseWindow:1b7d4c2a",
  "versionId": "EXA:Version:9e3f0a61",
  "ownerOrganisationId": 47,
  "status": "DRAFT",
  "validBetween": { "fromDate": "2026-11-09" },
  "purchaseWhen": "ADVANCE_AND_DAY_OF_TRAVEL",
  "minimumPeriodBeforeDeparture": "PT1H",
  "maximumPeriodBeforeDeparture": "P90D"
}
```

Note the two ids:

- `id` identifies the parameter. The product refers to it by this id.
- `versionId` identifies this version of the parameter. You use it when you send the version
  to test and publish it in [step 4](/guides/fare-data/4-test-and-publish).

The new version is a `DRAFT`, with effective dates that start today. You set the real effective dates when you send it to test.

## Use existing parameters

You can refer to any published parameter by its NeTEx id, including parameters that Entur or
other organisations own. You can't change parameters you don't own.

Find them with the list endpoints for each type in the
[Product parameters API](/apis/product-parameters-api).

## Next steps

[2. Create a product](/guides/fare-data/2-product)
