Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Any endpoint that needs an API key can answer:
- `403` with `"error": "API_KEY_SCOPE"`: the key's access doesn't cover this endpoint, such as a key limited to **Device sessions only** calling `GET /uploads/list`.
- `503` with the message "Could not validate the API key right now": the API couldn't check your key. Retry. It doesn't mean the key is invalid.

The [JUnit report](results.md#download-junit-report) and [HTML report](results.md#download-html-report) downloads answer an error with a `message` only.
The [JUnit report](results.md#download-junit-report) and [HTML report](results.md#download-html-report) downloads, and the [bundle manifests](results.md#download-zips-through-the-cdn), answer an error with a `message` only.

Three endpoints report client errors differently: [`GET /results/:uploadId`](results.md#get-results), [`GET /flows`](flows.md#get-flow-summaries) and [`GET /flows/runs`](flows.md#get-runs-for-a-flow) respond with HTTP `200` and report the error in the body instead:

Expand Down
103 changes: 103 additions & 0 deletions api/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ curl https://api.devicecloud.dev/results/7e12345f-eb12-12ec-a30b-bb1234f1d12a/re

## Download HTML report

::: tip
We recommend [Download ZIPs through the CDN](#download-zips-through-the-cdn) instead: `report-bundle` gives the same ZIP, built and served by our CDN.
:::

Returns a ZIP containing the HTML report together with the screenshots, videos and logs of every test in an upload (the latest attempt of each). An upload with no results in your team answers HTTP `404`.

```
Expand All @@ -153,6 +157,10 @@ curl https://api.devicecloud.dev/results/7e12345f-eb12-12ec-a30b-bb1234f1d12a/ht

## Download artifacts

::: tip
We recommend [Download ZIPs through the CDN](#download-zips-through-the-cdn) instead: `artifacts-bundle` gives the same ZIP, with the same `results` and `resultId` filters, built and served by our CDN.
:::

Returns a zip file containing logs, screenshots, and videos. Filter to all results or failing only. Each test's files sit in a folder named after its result ID (`<resultId>/logs/`, `<resultId>/screenshots/`, `<resultId>/videos/`), and a merged JUnit `report.xml` covering the whole upload is added at the root — see [Artifact Archive Structure](../artifacts/artifacts.md#artifact-archive-structure).

```
Expand Down Expand Up @@ -185,3 +193,98 @@ curl -X POST https://api.devicecloud.dev/results/7e12345f-eb12-12ec-a30b-bb1234f
-d '{"results": "ALL", "resultId": 4446290}' \
-o artifacts.zip
```

---

## Download ZIPs through the CDN

Gets the artifacts ZIP or the HTML report ZIP from DeviceCloud's CDN, which builds it. It takes two requests: one to the API for a signed manifest, then one to the CDN with that manifest, which answers with the ZIP. The ZIPs have the same layout as the [HTML report](#download-html-report) and [artifacts](#download-artifacts) downloads (see [Artifact Archive Structure](../artifacts/artifacts.md#artifact-archive-structure)). This is the recommended way to download them, and the one the `dcd` CLI uses: the CDN builds and serves the ZIP, so a large download doesn't have to pass through the API.

### 1. Get a manifest

```
GET /results/:uploadId/artifacts-bundle
GET /results/:uploadId/report-bundle
```

`artifacts-bundle` is for the artifacts ZIP and `report-bundle` for the HTML report ZIP. `artifacts-bundle` takes the same filters as [Download artifacts](#download-artifacts), as query parameters:

| Parameter | Values | Description |
|-----------|--------|-------------|
| `results` | `FAILED`, `ALL` | Which test artifacts to include. Leave it out for `ALL`. |
| `resultId` | A result ID (optional) | Only the files of the flow run this result belongs to: its first attempt and every retry, on that one device. `report.xml` then covers just that run. A value that isn't a positive whole number is a `400`, and a result that isn't in this upload is a `404`. |

**Response**

```json
{
"bundleUrl": "https://cdn.devicecloud.dev/bundle",
"manifest": "{\"version\":1,\"filename\":\"artifacts-failed.zip\",...}",
"sig": "Vb2y0pQ8xJ3kM1nR5tW7zA9cE4fH6iL0oS2uX8dG1qY",
"filename": "artifacts-failed.zip",
"entryCount": 42
}
```

* `bundleUrl` is where to send the manifest. Use it as given rather than hard-coding it.
* `manifest` and `sig` go to the CDN unchanged. Don't parse `manifest`: its contents may change.
* `filename` is a name you can save the ZIP under.
* `entryCount` is how many stored files the ZIP holds, not counting the generated `report.xml` or `report.html`.

A manifest expires an hour after it's issued, so get a new one for each download.

An upload with no results in your team answers HTTP `404`, with only a `message`. An upload with more than 9,000 files answers HTTP `413` with `message`, `entryCount` and `maxEntries`. To download one, ask `artifacts-bundle` for fewer files at a time, with `resultId` or `results=FAILED`.

### 2. Download the ZIP

Send `manifest` and `sig` as JSON to `bundleUrl`. Don't send your API key: the signature is what authorizes the request.

```
POST <bundleUrl>
```

```json
{ "manifest": "<manifest>", "sig": "<sig>" }
```

The answer is the ZIP, streamed as it's built. If a file can't be fetched partway through, the download ends early and leaves a truncated ZIP, so get a new manifest and try again. An error before the ZIP starts comes as plain text: `401` once the manifest has expired, `403` if `manifest` or `sig` doesn't match what the API issued, `400` for a malformed body, and `502` for a temporary problem on our side (retry).

**Example**

```bash
curl "https://api.devicecloud.dev/results/7e12345f-eb12-12ec-a30b-bb1234f1d12a/artifacts-bundle?results=FAILED" \
-H "x-app-api-key: <key>" \
-o bundle.json

jq '{manifest, sig}' bundle.json | curl -X POST "$(jq -r .bundleUrl bundle.json)" \
-H "Content-Type: application/json" \
--data-binary @- \
-o artifacts.zip
```

The same in Python, with only the standard library:

```python
import json
import shutil
import urllib.request

upload_id = "7e12345f-eb12-12ec-a30b-bb1234f1d12a"
manifest_request = urllib.request.Request(
f"https://api.devicecloud.dev/results/{upload_id}/artifacts-bundle?results=FAILED",
headers={"x-app-api-key": "<key>"},
)
with urllib.request.urlopen(manifest_request) as response:
bundle = json.load(response)

zip_request = urllib.request.Request(
bundle["bundleUrl"],
data=json.dumps({"manifest": bundle["manifest"], "sig": bundle["sig"]}).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(zip_request) as response, open("artifacts.zip", "wb") as out:
shutil.copyfileobj(response, out)
```

For the HTML report, request `report-bundle` instead of `artifacts-bundle`, with no query parameters.
Loading