Skip to content

Fix example for creating new version using workers.scripts.versions.create #2645

@huv1k

Description

@huv1k

Confirm this is a Typescript library issue and not an underlying Cloudflare API issue

  • This is an issue with the Typescript library

Describe the bug

Currently there is no clear way how to upload scripts using SDK. I was trying to use workers.scripts.versions.create methods, but there is clearly missing uploading actual scripts. When trying basic example:

async function deploy() {
  const client = new Cloudflare({
    apiToken: "****",
  });

  const version = await client.workers.scripts.versions.create("worker", {
    account_id: "****",
    metadata: {
      main_module: "index.js",
    },
  });

  console.log(version);
}

deploy().catch(console.error);

This always throws 400 with {"code":10021,"message":"could not read content for part metadata"}. Looking on various support forum there is issue with compatibility_date. Even setting this doesn't fix it I tried to add script content and metadata to body, but same result. Could you please provide clearer guidance in example how to create a new version? We want to use this to create gradual deployment programatically.

To Reproduce

  1. Create script
async function deploy() {
  const client = new Cloudflare({
    apiToken: "****",
  });

  const version = await client.workers.scripts.versions.create("worker", {
    account_id: "****",
    metadata: {
      main_module: "index.js",
    },
  });

  console.log(version);
}

deploy().catch(console.error);
  1. Add correct apiToken and account_id
  2. Run it node index.js
  3. There is error printed in terminal

Code snippets

OS

macOS Sequoia 15.5

Runtime version

Typescript 5.8.3

Library version

4.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions