Need help generating a valid token to call the API

For Workes & Pages, what is the name of the domain?

achecarro.com.br

What is the error number?

10000

What is the error message?

Authentication Error

What is the issue or error you’re encountering

I’m currently developing a automated php script to generate SSL certificates to our users domains, but when I try to create a custom hostname via the API, I can’t call the POST route for it, all I get is a Error 10000: Authentication Error. I call can the GET route for Custom Hostnames, even though I configured the token to have the permission to write and read

What steps have you taken to resolve the issue?

I’ve tried generating new tokens with different permissions but it changed nothing when trying to call the API.

What are the steps to reproduce the issue?

Generate a new token with SSL and Custom Hostnames write and read permissions and call the route https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/custom_hostnames with a POST method through php CURL, sending the bearer token in the request headers and the body containg the hostname, ssl method and type.

Code example:
`
private $headers = Array (
‘Authorization: Bearer {YOUR_TOKEN}’,
);

function generateCloudflareSSLCertificate($hostname, $sslMethod = 'txt', $sslType = 'dv') {

    $zoneId = {YOUR_ZONE_ID};

    $postFields = Array(
        'hostname' => $hostname,
        'ssl' => Array(
            'method' => $sslMethod,
            'type' => $sslType
        ),
    );
    if($json = $this->curlConnect($this->url.'/zones/'.$zoneId.'/custom_hostnames', null, null, $this->headers)) {
        $response = json_decode($json, true);
        var_dump($response);
    }
    if($json = $this->curlConnect($this->url.'/zones/'.$zoneId.'/custom_hostnames', null, $postFields, $this->headers)) {
        $response = json_decode($json, true);
        var_dump($response);
    }
}

`
The first var_dump should work as intended as it’s a GET request, but the second API call shouldn’t.

Screenshot of the error

I took steps to correct for that error. Sorry for the issues. If you keep getting the error, can you create an Account ticket and share your ticket number here? You can open an Account ticket here, https://dash.cloudflare.com/?to=/:account/support

Turns out I was just using the wrong Bearer Token for my zone.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.