For Workers & Pages, what is the name of the domain?
test com
What is the error number?
1434
What is the error message?
The SSL attribute is invalid. Please refer to the API documentation, check your input and try again.
What is the issue or error you’re encountering
Trying to send post request to /zones/{zone_id}/custom_hostnames
What steps have you taken to resolve the issue?
I am trying to send post request to /zones/{zone_id}/custom_hostnames (Cloudflare API | Custom Hostnames ) through PHP Laravel in this way:
$payload = [
'custom_metadata' => (object)[],
'hostname' => $hosting->customdomain,
'ssl' => ['method' => 'http', 'cloudflare_branding' => false, 'settings' => ['tls_1_3' => true]],
];
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config( 'cloudflare.api.token' )
])->post( config( 'cloudflare.api.baseuri' ) . '/custom_hostnames', $payload);
But it gives this error: The SSL attribute is invalid. Please refer to the API documentation, check your input and try again.
. If I remove the ssl attribute then it works fine.
Hi @zishanj ,
You need to include the type in your request
$payload = [
'custom_metadata' => (object)[],
'hostname' => $hosting->customdomain,
'ssl' => ['method' => 'http', 'type' => 'dv', 'cloudflare_branding' => false, 'settings' => ['tls_1_3' => true]],
];
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config( 'cloudflare.api.token' )
])->post( config( 'cloudflare.api.baseuri' ) . '/custom_hostnames', $payload);
It’s now giving this error Unable to decode the JSON request body. Please check your input and try again.
. Although the payload is JSON compatible.
The $payload is a PHP associative array, you need to encode it to json, or use json directly:
$payload = [
'custom_metadata' => (object)[],
'hostname' => $hosting->customdomain,
'ssl' => [
'method' => 'http',
'type' => 'dv',
'cloudflare_branding' => false,
'settings' => [
'tls_1_3' => true,
],
],
];
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config('cloudflare.api.token'),
'Content-Type' => 'application/json',
])->post(config('cloudflare.api.baseuri') . '/custom_hostnames', json_encode($payload));
Or the direct json
{
"hostname": "domain.com",
"ssl":{
"cloudflare_branding": false,
"method":"http",
"type":"dv"
},
"custom_metadata": {
"foo": "string"
}
}
I have tried this in curl with same error:
curl https://api.cloudflare.com/client/v4/zones/zone_id/custom_hostnames \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer [bearer_token]" \
-d '{
"hostname": "test.mydomain.com",
"ssl": {"method":"http"}
}'
Did some more testing in curl. If I add dv
attribute also then it works:
curl https://api.cloudflare.com/client/v4/zones/zone_id/custom_hostnames \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer bearer_token" \
-d '{
"hostname": "test.mydomain.com",
"ssl": {"method":"http", "type":"dv"}
}'
but if I am to add settings
attribute then it gives json error:
curl https://api.cloudflare.com/client/v4/zones/zone_id/custom_hostnames \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer bearer_token" \
-d '{
"hostname": "test.mydomain.com",
"ssl": {"method":"http", "type":"dv", "cloudflare_branding":false, "settings":{"tls_1_3":true}}
}'
Hi @zishanj ,
The tls_1_3 key expects a “on” | “off” string value, not a true|false boolean
curl https://api.cloudflare.com/client/v4/zones/zone_id/custom_hostnames
-H 'Content-Type: application/json'
-H 'Authorization: Bearer bearer_token'
-d '{
"hostname": "test.mydomain.com",
"ssl": {"method":"http", "type":"dv", "cloudflare_branding":false, "settings":{"tls_1_3":"on"}}
}'
yeah thanks … it works now. This type:dv
is required which is documented as optional in the doc. Works in PHP now.
1 Like
Technically the whole ssl key is optional, thus making the type technically optional.
There is a note further down the page
Level of validation to be used for this hostname. Domain validation (dv) must be used.
This looks more like a hint in selecting the best option for type
. Whereas the type
is not specifically mentioned anywhere as required if ssl
attribute is used.
1 Like
system
Closed
May 31, 2025, 6:36am
11
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.