Cloudflare Pages Wrangler Error

So I’m using NextJs Api routes. I use ShellJS to run the wrangler CLI inside Nextjs.

import shell from 'shelljs';

export default function handler(req, res) {
  console.log('Hello Node.js');
  process.env.CLOUDFLARE_ACCOUNT_ID = '123456;

shell.echo('hello world');
shell.exec('npx wrangler pages publish ../../../../../cf --project-name=test');

  res.status(200).json({ name: 'John Doe' });
}

Here’s the response -

Hello Node.js
X [ERROR] A request to the Cloudflare API (/accounts/123456 /pages/projects/test) failed.

Could not route to /accounts/123456 /pages/projects/test, perhaps your object identifier is invalid? [code: 7003]

No route for that URI [code: 7000]

So if you see after my account id 123456 there’s space. I think that’s causing the issue. But wrangler makes this request so I don’t know how to fix it.

I tried other libraries as well & same result.

If I use the child-process of NodeJS. I get an error saying fetch failed. No description or anything.

How do I solve this? I want to call an API & have the wrangler run to deploy new Cloudflare pages.

It is indeed.

Your script is setting the account ID incorrectly, obviously without the proper code it’s impossible to say why. But yeah, that’ll be the issue.

The above is my whole code. I’m trying to upload the demo files that Cloudflare Pages provides. You can test it out if possible it’s just the 3 lines of code being executed in Nodejs environment.

This code is invalid and your account ID isn’t 123456. So, this is not your real code.

All I can do is guess at what you edited and guess at what used to be there.

I’m not sure if I can post a real account Id. But that’s the only part that’s changed. You can re-create this exact issue with your account id as well. Or let me know if I should post it here.

Account IDs are not private. Please post the actual code you’re using.

1 Like

Sure here’s the full code -

Wrangler version 2.20.0

import shell from 'shelljs';

export default function handler(req, res) {
  process.env.CLOUDFLARE_ACCOUNT_ID = '267096448cd9e942d2130df8f6bad54b';

shell.echo('hello world');
shell.exec('npx wrangler pages publish ./cf --project-name=test' );

  res.status(200).json({ name: 'John Doe' });
}
X [ERROR] A request to the Cloudflare API (/accounts/267096448cd9e942d2130df8f6bad54b /pages/projects/test) failed.

Could not route to /accounts/267096448cd9e942d2130df8f6bad54b /pages/projects/test, perhaps your object identifier is invalid? [code: 7003]

No route for that URI [code: 7000]