Unable to Authenticate request with 10001 error code
I want to create a worker and put a script into it, based on the explorations i came upon this script, but I'm getting when i run the script (attached a file).
1 Reply
import { Console } from '@/helpers/logs'
import { CLOUDFLARE_ENDPOINT, HTTP_METHODS } from '@/data/constants'
import { CLOUDFLARE_EMAIL, CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID } from '@/data/constants/Envs'
const CreateWorker = async (slug: string, code: string): Promise<boolean> => {
try {
const workerCreation = await fetch(`${CLOUDFLARE_ENDPOINT}/accounts/${CLOUDFLARE_ACCOUNT_ID}/workers/services`, {
method: HTTP_METHODS.POST,
headers: {
'X-Auth-Email': CLOUDFLARE_EMAIL as string,
'X-Auth-Key': CLOUDFLARE_API_KEY as string,
'Content-Type': 'multipart/form-data'
},
body: JSON.stringify({
name: slug
})
})
const response = await workerCreation.json()
const success = response?.success
if (success) {
const form = new FormData()
form.append('metadata', JSON.stringify({ main_module: 'index.js', bindings: [] }))
form.append('index.js', new Blob([code], { type: 'application/javascript' }), 'index.js')
const workerCode = await fetch(`${CLOUDFLARE_ENDPOINT}/accounts/${CLOUDFLARE_ACCOUNT_ID}/workers/services/${slug}/content`, {
method: HTTP_METHODS.PUT,
headers: {
'X-Auth-Email': CLOUDFLARE_EMAIL as string,
'X-Auth-Key': CLOUDFLARE_API_KEY as string,
'Content-Type': 'application/json'
},
body: form
})
const response = await workerCode.json()
const success = response?.success
return success
}
else return false
}
catch (error) {
Console.Error('CreateWorker', error)
return false
}
}
export default CreateWorker
import { Console } from '@/helpers/logs'
import { CLOUDFLARE_ENDPOINT, HTTP_METHODS } from '@/data/constants'
import { CLOUDFLARE_EMAIL, CLOUDFLARE_API_KEY, CLOUDFLARE_ACCOUNT_ID } from '@/data/constants/Envs'
const CreateWorker = async (slug: string, code: string): Promise<boolean> => {
try {
const workerCreation = await fetch(`${CLOUDFLARE_ENDPOINT}/accounts/${CLOUDFLARE_ACCOUNT_ID}/workers/services`, {
method: HTTP_METHODS.POST,
headers: {
'X-Auth-Email': CLOUDFLARE_EMAIL as string,
'X-Auth-Key': CLOUDFLARE_API_KEY as string,
'Content-Type': 'multipart/form-data'
},
body: JSON.stringify({
name: slug
})
})
const response = await workerCreation.json()
const success = response?.success
if (success) {
const form = new FormData()
form.append('metadata', JSON.stringify({ main_module: 'index.js', bindings: [] }))
form.append('index.js', new Blob([code], { type: 'application/javascript' }), 'index.js')
const workerCode = await fetch(`${CLOUDFLARE_ENDPOINT}/accounts/${CLOUDFLARE_ACCOUNT_ID}/workers/services/${slug}/content`, {
method: HTTP_METHODS.PUT,
headers: {
'X-Auth-Email': CLOUDFLARE_EMAIL as string,
'X-Auth-Key': CLOUDFLARE_API_KEY as string,
'Content-Type': 'application/json'
},
body: form
})
const response = await workerCode.json()
const success = response?.success
return success
}
else return false
}
catch (error) {
Console.Error('CreateWorker', error)
return false
}
}
export default CreateWorker
{
success: false,
errors: [
{
code: 10001,
message: "Unable to authenticate request",
}
],
}
{
success: false,
errors: [
{
code: 10001,
message: "Unable to authenticate request",
}
],
}