# Stable download link

Downloads the newest release that has a file for the chosen platform and architecture. The link names no version or filename, so it stays the same when you publish a new release.

`GET /v1/products/{product}/download`

## Use cases

- Put a download button on your website that always leads to the newest file.
- Link to the newest beta, or to the newest version of one version line.
- Download the newest file on your server for a customer of a `licensed` product.

To add these links to a web page, see [Put download links on your page](../../guides/releases/updates-and-download-links/#put-download-links-on-your-page). To download one exact file, use [Download an artifact](../download-an-artifact/).

## File selection

The query parameters choose one release and one file of that release. The links in the Download links section of the product in the dashboard already name the parameters that each file needs.

Without `version`, the link leads to the newest published release that has a matching file. The release is from the channel of the link or a more stable channel. Without `channel`, the link uses `stable`. The rules are in [Newest release](../../concepts/releases-and-artifacts/#newest-release).

- A release without a matching file is skipped. A fix for Windows only does not change the macOS link.
- A `universal` build matches a link for any architecture. A build for the exact architecture wins over a `universal` build.
- A file without a platform or an architecture never matches a link that names one.
- If several files of the chosen release match, the link fails with the status 404. Add `filetype` or `filename` to the link. Seatify does not use an older release instead.
- A link without parameters works only when the newest release has one file.

`filename` chooses the file with this exact filename. A filename that contains the version leads only to that version.

With `version`, the link leads to this exact release. The link then ignores `channel` and `constraint`. Send the version without a `v` prefix. In the query string, encode the plus sign of build metadata as `%2B`, such as `version=2.1.0%2B42`.

A draft release, a yanked release and a file whose upload has not finished are never chosen. An exact version of a draft or a yanked release answers with the status 404.

## Download link

A download answers with the status 303 and no body. The `Location` header is a signed download link. HTTP clients and browsers follow the redirect by default.

- The link expires. Request this endpoint again for a new link.
- The link does not need a license key.
- The link accepts a `Range` header, so your application can resume a download that stopped.
- The file is saved under its filename.
- An expired link answers with the status 403 and the text `The link has expired.`

The redirect is not signed. Verify the file with its SHA-256 and its signature before your application installs it. See [Verifying files](../../concepts/releases-and-artifacts/#verifying-files).

## License checks

The stable download link checks the license key when the request sends one. A refused license answers with the status 403 and this body:

```json
{
  "valid": false,
  "reason": "suspended"
}
```

The reason is `product_mismatch`, `suspended`, `expired` or `release_not_covered`. See [License checks](../authentication/#license-checks).

A license that expired under the Perpetual fallback rule gets only the releases that were published on or before its expiry date. A [backdated release](../../concepts/releases-and-artifacts/#backdated-releases) counts as published on its backdated date.

- Without `version`, the link leads to the newest of these releases.
- With the `version` of a release that was published later, the answer has the reason `release_not_covered`.

Seatify checks the license before it looks for the release. A refused license gets the status 403, also when no file matches.

## Download allowance

On the Free plan, a download is refused when your account used the download allowance of the month. The answer has the status 403 and this body:

```json
{
  "valid": false,
  "reason": "download_limit_reached"
}
```

Seatify checks the allowance before the license checks and before it looks for the release. The refusal also applies to an `open` product without a license key. A refused download is not counted, and it records no activity. See [Downloads](../../concepts/plans-and-limits/#downloads).

## Downloads and activity

- Each redirect counts as one download of the artifact. A refused request and a request that answers 404 are not counted.
- A request with a license key records a download on the license. A refused license is recorded too. See [Activity](../../concepts/activity/).
- A request without a license key, on an `open` product, records no activity. A request that answers 404 records no activity.

## Authentication

Send the license key of the customer. A product with the `open` distribution setting does not require a key. See [Authentication](../authentication/).

A browser sends no header when it follows a link. So a link on a web page works only for an `open` product. For a `licensed` product, your server requests the link. See [Licensed products](../../guides/releases/updates-and-download-links/#licensed-products).

## Request

`{product}` is the ID of the product. The request has no body.

| Header | Required | Description |
| --- | --- | --- |
| `Seatify-License-Key` | For a `licensed` product | The license key of the customer. For an `open` product, a key that the request sends must be valid. |

The redirect is not signed. The API ignores the `Seatify-Nonce` and `Seatify-Signing-Key` headers on this endpoint.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `platform` | string | No | The platform of the file: `darwin`, `windows`, `linux`, `ios`, `android` or `freebsd`. See [Platforms and architectures](../../concepts/releases-and-artifacts/#platforms-and-architectures). |
| `arch` | string | No | The architecture of the file: `amd64`, `arm64`, `x86`, `arm` or `universal`. |
| `filetype` | string | No | The file type, such as `dmg`, `exe` or `tar.gz`. It is the extension of the filename without the dot. |
| `filename` | string | No | The exact filename of the file. The filename is case-sensitive. |
| `version` | string | No | An exact version, such as `2.1.0`. Without it, the link leads to the newest release. See [File selection](#file-selection). |
| `channel` | string | No | The [channel](../../concepts/releases-and-artifacts/#channels) of the newest release. The release is from this channel or a more stable channel. The `dev` channel returns only `dev` releases. The default is `stable`. An exact version ignores it. |
| `constraint` | string | No | A major version, such as `2`, or a major and minor version, such as `2.1`. The constraint `2` allows only `2.x.y` versions. The constraint `2.1` allows only `2.1.y` versions. An exact version ignores it. |

## Response

A download answers with the status 303 and no body.

| Header | Description |
| --- | --- |
| `Location` | The signed download link. See [Download link](#download-link). |
| `Cache-Control` | The value is `no-store`. Do not cache the redirect. |

A refused license answers with the status 403 and a JSON body.

| Field | Type | Description |
| --- | --- | --- |
| `valid` | boolean | The value is always `false`. |
| `reason` | string | The reason of the refusal. See [License checks](#license-checks). |

## Errors

| Status | Reason | Description |
| --- | --- | --- |
| 400 | `The submitted details are not valid.` | A query parameter is not valid. The `errors` field names the parameter. |
| 401 | `A license key is required.` | The product is `licensed`, and the request has no `Seatify-License-Key` header, or the header is empty. |
| 401 | `The license key is not valid.` | No license in your account has this key. This applies to an `open` product too. |
| 403 | `product_mismatch`, `suspended`, `expired` or `release_not_covered` | The license is refused. See [License checks](#license-checks). |
| 403 | `download_limit_reached` | Your account used the download allowance of the Free plan for this month. See [Download allowance](#download-allowance). |
| 404 | `The product was not found.` | No product has this ID. |
| 404 | `The artifact was not found.` | No published release in the channel and the constraint has a matching file. With `version`, the release is not published or has no matching file. |
| 404 | `Several artifacts match the request. Name a filetype, or the filename itself.` | Several files of the chosen release match. See [File selection](#file-selection). |
| 429 | `There are too many requests. Try again later.` | See [Rate limits](../#rate-limits). |

See [Errors](../#errors).

## Example

Download the newest macOS file.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl --fail --location --remote-name --remote-header-name \
  -H "Seatify-License-Key: $LICENSE_KEY" \
  "https://dist.seatify.dev/v1/products/$PRODUCT_ID/download?platform=darwin&arch=universal&filetype=zip"
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
import Foundation

struct DownloadFailed: Error {}

let url = URL(string: "https://dist.seatify.dev/v1/products/\(productID)/download?platform=darwin&arch=universal&filetype=zip")!

var request = URLRequest(url: url)
request.setValue(licenseKey, forHTTPHeaderField: "Seatify-License-Key")

let (fileURL, response) = try await URLSession.shared.download(for: request)
guard (response as? HTTPURLResponse)?.statusCode == 200 else { throw DownloadFailed() }

let filename = response.suggestedFilename
```
{{< /tab >}}
{{< tab name="C#" >}}
```csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Seatify-License-Key", licenseKey);

using var response = await client.GetAsync(
    $"https://dist.seatify.dev/v1/products/{productId}/download?platform=darwin&arch=universal&filetype=zip",
    HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();

var filename = Path.GetFileName(response.RequestMessage!.RequestUri!.LocalPath);

await using var file = File.Create(filename);
await response.Content.CopyToAsync(file);
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
req, err := http.NewRequest("GET", "https://dist.seatify.dev/v1/products/"+productID+"/download?platform=darwin&arch=universal&filetype=zip", nil)
if err != nil {
	return err
}
req.Header.Set("Seatify-License-Key", licenseKey)

res, err := http.DefaultClient.Do(req)
if err != nil {
	return err
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
	return fmt.Errorf("the download failed with the status %d", res.StatusCode)
}

file, err := os.Create(path.Base(res.Request.URL.Path))
if err != nil {
	return err
}
defer file.Close()

_, err = io.Copy(file, res.Body)
```
{{< /tab >}}
{{< tab name="JavaScript" >}}
```javascript
const response = await fetch(
  `https://dist.seatify.dev/v1/products/${productId}/download?platform=darwin&arch=universal&filetype=zip`,
  { headers: { "Seatify-License-Key": licenseKey } },
);
if (!response.ok) {
  throw new Error(`The download failed with the status ${response.status}.`);
}
const filename = decodeURIComponent(new URL(response.url).pathname.split("/").pop());
const file = await response.arrayBuffer();
```
{{< /tab >}}
{{< /tabs >}}

The first answer is the redirect:

```text
HTTP/1.1 303 See Other
Cache-Control: no-store
Location: <signed download link>
```

A link that matches several files answers with the status 404:

```json
{
  "message": "Several artifacts match the request. Name a filetype, or the filename itself."
}
```

