Programmatically deploy to Cloudflare Pages using API

Hello, I am trying to use the api to deploy some static files(without git project, I want direct upload). Wrangler works fine however I need to do it using the api. At first I tried using the curl request the docs propose to create a project:
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects \
-H 'Content-Type: application/json' \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
-d '{
"name": "NextJS Blog",
"production_branch": "main"
}'
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects \
-H 'Content-Type: application/json' \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_API_KEY" \
-d '{
"name": "NextJS Blog",
"production_branch": "main"
}'
which returns:
{"success":false,"errors":[{"code":10001,"message":"Unable to authenticate request"}]}
{"success":false,"errors":[{"code":10001,"message":"Unable to authenticate request"}]}
Then I tried using the python library which needed more fields than the docs to make it work:
from cloudflare import Cloudflare

client = Cloudflare(
api_token="Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY",
)
project = client.pages.projects.create(
account_id="023e105f4ecef8ad9ca31a8372d0c353",
name="my-project123",
production_branch="main"
)
print(project.id)
from cloudflare import Cloudflare

client = Cloudflare(
api_token="Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY",
)
project = client.pages.projects.create(
account_id="023e105f4ecef8ad9ca31a8372d0c353",
name="my-project123",
production_branch="main"
)
print(project.id)
however I managed to make it work but the deployment endpoint didn't work:
from cloudflare import Cloudflare

client = Cloudflare(
api_token="Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY",
)
deployment = client.pages.projects.deployments.create(
project_name="this-is-my-project-01",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(deployment.id)
from cloudflare import Cloudflare

client = Cloudflare(
api_token="Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY",
)
deployment = client.pages.projects.deployments.create(
project_name="this-is-my-project-01",
account_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(deployment.id)
Response:
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 8000096, 'message': 'A "manifest" field was expected in the request body but was not provided.'}], 'messages': []}
cloudflare.BadRequestError: Error code: 400 - {'result': None, 'success': False, 'errors': [{'code': 8000096, 'message': 'A "manifest" field was expected in the request body but was not provided.'}], 'messages': []}
The manifest field is not documented anywhere, am I missing something? My account id is: 12172aa469d19f4bc6f5f15a7875cb46
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?