Create project with CF API - Incomplete info

When I create a new CF Pages project using the API: https://developers.cloudflare.com/api/operations/pages-project-create-project The request is successful but when I go to the dashboard I see that the "Builds & deployments" information is missing. And I am sending it in the payload as requested by the API. The sent payload looks something like this:
payload = {
"build_config": {
"build_command": f "yarn build --filter={APP_NAME}",
"destination_dir":"/something",
"root_dir":"/",
},
"canonical_deployment": none,
"deployment_configs": {
"preview": {
"compatibility_date": "2022-01-01",
"compatibility_flags": [ "url_standard"],
"env_vars": secrets_pages,
},
"production": {
"compatibility_date": "2022-01-01",
"compatibility_flags": ["url_standard"],
"env_vars": secrets_pages,
},
},
"latest_deployment": none,
"name": f"{APP_NAME}-{HASH}",
"production_branch": "something".
}
payload = {
"build_config": {
"build_command": f "yarn build --filter={APP_NAME}",
"destination_dir":"/something",
"root_dir":"/",
},
"canonical_deployment": none,
"deployment_configs": {
"preview": {
"compatibility_date": "2022-01-01",
"compatibility_flags": [ "url_standard"],
"env_vars": secrets_pages,
},
"production": {
"compatibility_date": "2022-01-01",
"compatibility_flags": ["url_standard"],
"env_vars": secrets_pages,
},
},
"latest_deployment": none,
"name": f"{APP_NAME}-{HASH}",
"production_branch": "something".
}
I already made sure that all variables are parsed properly and the resulting payload has the desired data. But I still can't see that "Builds & deployments" window when I go to open the dashboard in CF. All this is running in a github action for particular issues of the repository where the applications live.
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
8 Replies
Walshy
Walshy2y ago
You're missing the "source" object which defines the GitHub/GitLab repo
fernando
fernandoOP2y ago
hey @walshydev when I pass the object "source" inside the payload, I get a 400 saying that "The request body is incorrect. The request body may have an invalid JSON type or missing required keys. Refer to https://developers.cloudflare.com/api."" The payload with the source looks like this:
payload = {
"source": {
"type": "github",
"config": {
"owner": "OWNER_NAME",
"repo": "REPO_NAME",
"production_branch": "master",
"pr_comments_enabled": "true",
"deployments_enabled": "true",
"production_deployments_enabled": "true",
"preview_deployment_setting": "all",
"preview_branch_includes": ["branch_name"],
"preview_branch_excludes": [],
}
},
"build_config": {
"build_command": f "yarn build --filter={APP_NAME}",
"destination_dir": "algo",
"root_dir":"/",
},
"canonical_deployment": none,
"deployment_configs": {
"preview": {
"fecha_compatibilidad": "2022-01-01",
"compatibility_flags": [ "url_standard"],
"env_vars": secrets_pages,
},
"production": {
"fecha_compatibilidad": "2022-01-01",
"compatibility_flags": ["url_standard"],
"env_vars": secrets_pages,
},
},
"latest_deployment": none,
"name": f"{APP_NAME}-{HASH}",
"production_branch": "branch_name".
}
payload = {
"source": {
"type": "github",
"config": {
"owner": "OWNER_NAME",
"repo": "REPO_NAME",
"production_branch": "master",
"pr_comments_enabled": "true",
"deployments_enabled": "true",
"production_deployments_enabled": "true",
"preview_deployment_setting": "all",
"preview_branch_includes": ["branch_name"],
"preview_branch_excludes": [],
}
},
"build_config": {
"build_command": f "yarn build --filter={APP_NAME}",
"destination_dir": "algo",
"root_dir":"/",
},
"canonical_deployment": none,
"deployment_configs": {
"preview": {
"fecha_compatibilidad": "2022-01-01",
"compatibility_flags": [ "url_standard"],
"env_vars": secrets_pages,
},
"production": {
"fecha_compatibilidad": "2022-01-01",
"compatibility_flags": ["url_standard"],
"env_vars": secrets_pages,
},
},
"latest_deployment": none,
"name": f"{APP_NAME}-{HASH}",
"production_branch": "branch_name".
}
Btw the API documentation, doesn't mention anything about a "source" object.
fernando
fernandoOP2y ago
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
Walshy
Walshy2y ago
You're passing booleans as a string there
fernando
fernandoOP2y ago
nootlikethis Is there any documentation detailing this? As I mentioned in Pages Project / Create Project, they don't mention anything about the "source" object.
fernando
fernandoOP2y ago
When correcting the boolean, now it says: "Missing project source configuration. Specify a GitHub/GitLab repository owner and repository name." But that information is already in the payload in the source object.
Walshy
Walshy2y ago
Key is repo_name not repo Go SDK has the APIs implemented, you can see types here: https://github.com/cloudflare/cloudflare-go/blob/master/pages_project.go#L20-L51
fernando
fernandoOP2y ago
MeowHeartCloudflare great! thank you so much, this is so helpful!!!!
Want results from more Discord servers?
Add your server