Skip to content

[Workers] Add Builds API guide with workflow examples#28229

Merged
yomna-shousha merged 9 commits into
productionfrom
yomna/workers-builds-api-guide
Mar 30, 2026
Merged

[Workers] Add Builds API guide with workflow examples#28229
yomna-shousha merged 9 commits into
productionfrom
yomna/workers-builds-api-guide

Conversation

@yomna-shousha

@yomna-shousha yomna-shousha commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Addressed bonk's review

This PR adds a new guide for using the Workers Builds API.

The guide covers:

  • Required API token permissions (Workers Builds Configuration + Workers Scripts Read)
  • The Worker tag vs Worker name distinction (external_script_id)
  • Step-by-step workflow: get Worker tag → get trigger UUID → trigger builds
  • Production vs preview triggers and environment variables
  • Example scripts for redeploying and setting up builds from scratch

- Document required permissions (Workers Builds Configuration + Workers Scripts Read)
- Explain Worker tag vs Worker name (external_script_id) distinction
- Add complete workflow: get Worker tag → get trigger UUID → work with builds
- Include production vs preview trigger setup with environment variables
- Add redeploy script example for refreshing build-time data
- Add end-to-end setup example from GitHub repo connection to first build
- Add troubleshooting section for common errors
@yomna-shousha

Copy link
Copy Markdown
Contributor Author

/bonk review this PR using the docs agent guidelines

@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/assets/images/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @cloudflare/wrangler, @mattietk
/src/content/docs/workers/ci-cd/ @irvinebroque, @aninibread, @GregBrimble, @cloudflare/pcx-technical-writing, @yomna-shousha

@ask-bonk

ask-bonk Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Review complete. The findings are summarized above. No build-breaking issues were found, and the three recommended changes (#6 troubleshooting overlap, #8 editorial tone, #9 ofetch) are all minor improvements.

github run

- Remove editorial tone about API docs (line 37)
- Simplify troubleshooting section, link to dedicated troubleshoot page
- Replace ofetch with built-in fetch in redeploy example
@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

@irvinebroque irvinebroque left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure that references to the REST API link back to the relevant links to Builds API docs at api.cloudflare.com


### 1. Create an API token with the correct permissions

The Builds API requires a user-scoped API token with specific permissions. Create your token at [dash.cloudflare.com/profile/api-tokens](https://dash.cloudflare.com/profile/api-tokens).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually require user scoped? Or is it just that in dash we default to user scoped for ?

| Permission | Access | Why you need it |
|------------|--------|-----------------|
| Workers Builds Configuration | Edit | Trigger builds, update triggers, manage environment variables |
| Workers Scripts | Read | Retrieve Worker tags (required for all Builds API calls) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stritt @AdamBouhmad if dash supported deeplinking to API token creation, with specific permissions (or future: roles) as a query param

Then from docs like this we could send someone straight into creating a token with exactly the right permissions / roles

cc @vy-ton


Here is the typical workflow for interacting with the Builds API:

```txt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love having diagram here — maybe worth experimenting with conveying this via Mermaid? Will render nicely


Call the Workers Scripts API to list all your Workers and find the `tag` for the Worker you want to work with:

```bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal of this guide to show you how you could manually do this via CLI or show you a bit of code that you might write in TypeScript to program around the builds API and have it do things?

┌─────────────────────────────────────────────────────────────────┐
│ 2. Get trigger UUID (using the Worker tag) │

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point I'm not sure we have explained what a trigger is? Does someone need to understand that in order to follow?

- Clarify user-scoped token requirement and link to build token docs
- Update Worker tags section title to include external_script_id
- Rewrite trigger explanation with production/preview context
- Revert to ASCII diagrams for workflow overview
- Restructure Examples section with diagrams for each use case
- Add multiple sources for obtaining build_uuid
- Fix anchor links and API reference URLs
@yomna-shousha

Copy link
Copy Markdown
Contributor Author

/bonk Task: Convert ASCII diagrams to Mermaid in the Builds API reference
Convert the three ASCII flowchart diagrams in /Users/yomnashousha/cloudflare-docs/src/content/docs/workers/ci-cd/builds/api-reference.mdx to Mermaid format.
Diagram locations:

  1. Workflow overview (around line 64) - General 3-step workflow
  2. Set up Workers Builds from scratch (around line 289) - 6-step setup flow
  3. Redeploy current deployment (around line 474) - 3-step redeploy flow

Make them even more detailed than the ASCII diagrams based on the text they represent if need be

Co-authored-by: yomna-shousha <yomna-shousha@users.noreply.github.com>
@ask-bonk

ask-bonk Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Zero errors. All three ASCII diagrams have been successfully converted to Mermaid format. Here's a summary of the changes:

Diagram 1: Workflow overview (line 68)

  • Converted from ASCII boxes to a flowchart TD with a decision node (diamond shape) at step 3 that branches out to the four build operations: trigger, list, get logs, and cancel
  • Added the "Cancel a build" operation which wasn't in the original ASCII but is documented in the page

Diagram 2: Set up Workers Builds from scratch (line 294)

  • Converted the 6-step linear flow to a flowchart that shows the fork at step 4 where production and preview triggers are created in parallel, then converge back at step 5 (environment variables)
  • Added detail about the different deploy commands (wrangler deploy vs wrangler versions upload) and branch patterns directly in the diagram nodes

Diagram 3: Redeploy current deployment (line 452)

  • Converted the 3-step linear flow with expanded descriptions explaining the purpose of each step (finding the live deployment, looking up the original build metadata, and rebuilding with same parameters)

github run

- Fix anchor link (#3-understand-triggers → #3-what-is-a-trigger)
@yomna-shousha
yomna-shousha force-pushed the yomna/workers-builds-api-guide branch from c4de607 to 14e3049 Compare February 24, 2026 06:13
@yomna-shousha

Copy link
Copy Markdown
Contributor Author

/bonk instead of &{tag&}, &{uuid&}, and &{name&} can you make sure the correct fields are generated if it is incorrect
can you also make the Redeploy current deployment mermaid diagram horizontal

can you remove the text after the endpoint for all diagrams, except ones that are like → note account ID

for all mermaid diagrams, can you bold the title instead of the endpoint

do you need an endpoint for these: Production trigger and Preview trigger (optional)

Co-authored-by: yomna-shousha <yomna-shousha@users.noreply.github.com>
@ask-bonk

ask-bonk Bot commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

All changes are complete. Here's a summary of what was changed across all three Mermaid diagrams:

Diagram 1: Workflow overview (line 68)

  • Fixed placeholders: {tag}{worker_tag}, {uuid}{trigger_uuid} / {build_uuid} (matching the curl commands)
  • Bolded titles instead of endpoints (e.g., <strong>1. Get Worker tag</strong> instead of <strong>GET /workers/scripts</strong>)
  • Removed descriptive text after endpoints (e.g., removed "Find your Worker and note the tag UUID")

Diagram 2: Set up Workers Builds from scratch (line 294)

  • Fixed placeholder: {uuid}{trigger_uuid}
  • Bolded titles instead of endpoints
  • Removed descriptive text after endpoints (e.g., removed "Links your GitHub repo to Cloudflare", "Save the repo_connection_uuid")
  • Kept the → note account ID / → note repo ID annotations on the GitHub API calls (as requested)
  • No endpoints on Production/Preview trigger nodes — they are configuration sub-items of step 4 (which already shows POST /builds/triggers), not separate API calls

Diagram 3: Redeploy current deployment (line 452)

  • Changed to horizontal layout (flowchart LR instead of flowchart TD)
  • Fixed placeholders: {name}{worker_name}, {id}{version_id}, {uuid}{trigger_uuid}
  • Bolded titles instead of endpoints
  • Removed descriptive text after endpoints (e.g., removed "Find the current live deployment and note the version_id")

github run

@github-actions

Copy link
Copy Markdown
Contributor

Hey there, we've marked this pull request as stale because there's no recent activity on it. This label is helps us identify PRs that might need updates (or to be closed out by our team if no longer relevant).

@github-actions github-actions Bot added the stale label Mar 11, 2026
@yomna-shousha
yomna-shousha requested review from a team as code owners March 30, 2026 15:08
```bash
curl -s "https://api.cloudflare.com/client/v4/accounts/{account_id}/builds/workers/{worker_tag}/triggers" \
--header "Authorization: Bearer <API_TOKEN>" \
| jq '.result[] | {trigger_uuid, trigger_name, branch_includes, branch_excludes}'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we comfortable assuming jq is installed for everyone? It isn't a default package on any common OSes. Even just a link out to where you can download it would be helpful for people that are unfamiliar.


Save the `trigger_uuid` for the trigger you want to work with. Remember, you will have at most two triggers: one for your production branch (for example, `main`) that deploys to your live Worker, and optionally one for all other branches that creates preview deployments.

## Step 3: Work with builds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kinda weird to talk about using a trigger before you show how to create one. I know that comes later on in the doc, but I'd consider flipping the order.


The response includes `build_uuid` for each build, which you need for getting logs or canceling builds.

### Get build logs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a WebSocket streaming endpoint we want to document?

Comment on lines +494 to +497
--data '{
"branch": "{branch}",
"commit_hash": "{commit_hash}"
}'

@GregBrimble GregBrimble Mar 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said earlier that you can specify branch "or" commit_hash. Is it "and/or"?

@GregBrimble GregBrimble left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small-ish nits

@yomna-shousha
yomna-shousha enabled auto-merge (squash) March 30, 2026 17:14
@yomna-shousha
yomna-shousha merged commit c9f24c2 into production Mar 30, 2026
12 checks passed
@yomna-shousha
yomna-shousha deleted the yomna/workers-builds-api-guide branch March 30, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:workers Related to Workers product size/l stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants