Cannot update worker settings via API

I am using D1 bindings in my workers. I am deploying my workers using terraform. Terraform does not support D1 until GA, so after every CI deploy, the binding set via dashboard ‘ClickOps’ is removed.
I thought I can fix this, by scripting CF API call after terraform deploy as temporary measure.

Despite following API docs here I am getting error responses.

My code

// for brevity we'll try to update compatibility date only
  const url = `${process.env.CLOUDFLARE_ACCOUNT_ID}/workers/scripts/${SERVICE_NAME}/settings`;
  const body = new FormData();
  body.set('settings', JSON.stringify({ compatibility_date: '2022-04-05' }));
  const options: RequestInit = {
    method: 'PATCH',
    headers: {
      'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001',
      Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`,
  const result: any = await fetch(url, options).then(async res => res.json());

Settings are updated

Getting the following error

  result: null,
  success: false,
  errors: [
    { code: 10201, message: 'workers.api.error.missing_settings_part' }
  messages: []

Googling didn’t bring any meaningful results other then the one here
Any help/advice would be appreciated.
Also, what is the timeframe for D1 General Availability?

So, a little further down in the reddit article you linked someone found the answer…

I’ll reiterate here to hopefully save someone elses sanity:

What the request expects is a content type of multipart/form-data and an attached json encoded file called settings.

1 Like