# Download an artifact

Redirects to a signed link that downloads one artifact of a release.

`GET /v1/products/{product}/releases/{version}/artifacts/{filename}`

## Use cases

- Download the update that [Check for an update](../check-for-an-update/) offers.
- Download a file that [Get a release](../get-a-release/) or [List releases](../list-releases/) returns.
- Link to one exact version of a file.

The `url` of each artifact in these answers is the URL of this endpoint. To link to the newest file on a download page, use the [stable download link](../stable-download-link/).

## 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).

## Versions and filenames

`{version}` is the exact version of the release, such as `2.1.0` or `2.1.0-beta.1`. Send the version without a `v` prefix. A version with build metadata, such as `2.1.0+42`, can have the plus sign as is or encoded as `%2B`.

`latest` is not a version on this endpoint. It answers with the status 404. To download the newest file, use the [stable download link](../stable-download-link/).

`{filename}` is the filename of the artifact. The filename is case-sensitive. Encode characters such as spaces in the path.

A draft release, a yanked release and a file whose upload has not finished answer with the status 404. That is the same answer as a version or a filename that does not exist.

## License checks

Download an artifact 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 can download 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. A release that was published later answers with the reason `release_not_covered`.

Seatify checks the license before it looks for the release. A refused license gets the status 403, also for a version or a filename that does not exist.

## 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/).

## Request

`{product}` is the ID of the product. See [Versions and filenames](#versions-and-filenames) for `{version}` and `{filename}`. The request has no body and no query parameters.

| 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.

## 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 |
| --- | --- | --- |
| 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 has this version, or the release has no finished file with this filename. |
| 429 | `There are too many requests. Try again later.` | See [Rate limits](../#rate-limits). |

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

## Example

Download the macOS file of version `1.4.0`.

{{< tabs >}}
{{< tab name="curl" >}}
```bash
curl --fail --location --remote-name \
  -H "Seatify-License-Key: $LICENSE_KEY" \
  https://dist.seatify.dev/v1/products/$PRODUCT_ID/releases/1.4.0/artifacts/BEACON-1.4.0.zip
```
{{< /tab >}}
{{< tab name="Swift" >}}
```swift
import Foundation

struct DownloadFailed: Error {}

let url = URL(string: "https://dist.seatify.dev/v1/products/\(productID)/releases/1.4.0/artifacts/BEACON-1.4.0.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() }
```
{{< /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}/releases/1.4.0/artifacts/BEACON-1.4.0.zip",
    HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();

await using var file = File.Create("BEACON-1.4.0.zip");
await response.Content.CopyToAsync(file);
```
{{< /tab >}}
{{< tab name="Go" >}}
```go
req, err := http.NewRequest("GET", "https://dist.seatify.dev/v1/products/"+productID+"/releases/1.4.0/artifacts/BEACON-1.4.0.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("BEACON-1.4.0.zip")
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}/releases/1.4.0/artifacts/BEACON-1.4.0.zip`,
  { headers: { "Seatify-License-Key": licenseKey } },
);
if (!response.ok) {
  throw new Error(`The download failed with the status ${response.status}.`);
}
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 suspended license answers with the status 403:

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

