BreezeChMS / breeze-api-v1

The Breeze API v1 allows you to build custom applications integrated with the Breeze database.
https://www.breezechms.com/api
5 stars 3 forks source link

Permission Denied - API key () does not match subdomain #5

Open StanleyBonhomme opened 3 years ago

StanleyBonhomme commented 3 years ago

DISCLAIMER: Breeze does not actively monitor the contents of posted messages, is not responsible for any messages posted, does not vouch for or warrant the accuracy, completeness or usefulness of any message, and is not responsible for the contents of any message.

"{\"success\":false,\"errors\":[\"Permission Denied - API key () does not match subdomain (myredemption)\"]}"

This can't be right as the subdomain is correct and the API key is correct.

The expected behavior is for the data to be displayed

My browser is Chrome, OS is Windows, Language is PHP

Jesseu5 commented 2 years ago

Hi @StanleyBonhomme , did this ever get resolved as I am running into the same issue?

StanleyBonhomme commented 2 years ago

@Jesseu5 Hey yes i was able to resolve this issue. Below isi the a modified breeze.php file that fixes any warnings.

<?php

class Breeze {

    var $api_key;

    // validate

    // Fix Deprciation Error - https://stackoverflow.com/questions/37100373/php-deprecated-methods-with-the-same-name

    function __construct($passed_api_key) {

        // set API key which can be accessed throughout class

        $this->api_key = $passed_api_key;

    }

    // fetch request

     public function url($url) {

        // url encode all variables if variables found

    if (strpos($url,'?') !== false) {

        $base_url = substr( $url, 0, strpos( $url, '?' ) + 1 );

        $parts = parse_url($url);

        parse_str($parts['query'], $parameters);

        foreach($parameters as $name => $value) {

            $base_url .= "&" . $name . "=".urlencode($value);

        }

        $url = $base_url;

    }

        $options = array(

            CURLOPT_HTTPHEADER => array('Api-key: ' . $this->api_key),  // send API key in header

            CURLOPT_RETURNTRANSFER => true,                             // return web page

            CURLOPT_HEADER         => false,                            // don't return headers

            CURLOPT_FOLLOWLOCATION => true,                             // follow redirects

            CURLOPT_ENCODING       => "",                               // handle all encodings

            CURLOPT_USERAGENT      => "user",                           // who am i

            CURLOPT_AUTOREFERER    => true,                             // set referer on redirect

            CURLOPT_CONNECTTIMEOUT => 120,                              // timeout on connect

            CURLOPT_TIMEOUT        => 120,                              // timeout on response

            CURLOPT_MAXREDIRS      => 10,                               // stop after 10 redirects

            CURLOPT_SSL_VERIFYPEER => false                             // Disabled SSL Cert checks (if enabled, ensure path for CURLOPT_CAINFO is correct)

            //CURLOPT_CAINFO           => "breeze/cacert.pem",          // security certificate

            //CURLOPT_SSLVERSION        => 3                            // set correct SSL version

        );

        // get page data

        $ch      = curl_init( $url );

        curl_setopt_array( $ch, $options );

        $content = curl_exec( $ch );

        $err     = curl_errno( $ch );

        $errmsg  = curl_error( $ch );

        $header  = curl_getinfo( $ch );

        curl_close( $ch );

        // set to variables

        $header['errno']   = $err;

        $header['errmsg']  = $errmsg;

        $header['content'] = $content;

        if(empty($header['content']) || $header['content'] == false) {

            return $header['errmsg'];

        }

        // return content

        return $header['content'];
     }
}

?>

Also here is some is the code in order to call the api index.php 👍

<?php

require_once('breeze/breeze.php');
$breeze = new Breeze('your_api_key');
$subdomain = 'https://yoursubdomain.breezechms.com/api/';

$people = $breeze->url($subdomain . '/people/');

// get all breeze ids for people updated since 2016-1-25
$summary = $breeze->url($subdomain . '/account/summary');

// List People
$list_people = $breeze->url($subdomain . '/people/');

// Show Person
$person = $breeze->url($subdomain . '/people/15860394');

// Set to Data Variable
$data = $people;

// Add Headers to Response
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json; charset=UTF-8');
$myJSON = json_encode(json_decode($data), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

// Json Response
echo $myJSON;

?>

Feel free to use the example code. It should work.

Jesseu5 commented 2 years ago

Thank you so much that worked!

Jesse

From: Stanley Bonhomme @.> Reply-To: BreezeChMS/breeze-api-v1 @.> Date: Wednesday, December 22, 2021 at 8:02 PM To: BreezeChMS/breeze-api-v1 @.> Cc: Jesseu5 @.>, Mention @.***> Subject: Re: [BreezeChMS/breeze-api-v1] Permission Denied - API key () does not match subdomain (#5)

@Jesseu5 Hey yes i was able to resolve this issue. Below isi the a modified breeze.php file that fixes any warnings.

`<?php

class Breeze { var $api_key;

// validate

// Fix Deprciation Error - https://stackoverflow.com/questions/37100373/php-deprecated-methods-with-the-same-name

function __construct($passed_api_key) {

    // set API key which can be accessed throughout class

    $this->api_key = $passed_api_key;

}

// fetch request

public function url($url) {

    // url encode all variables if variables found

if (strpos($url,'?') !== false) {

    $base_url = substr( $url, 0, strpos( $url, '?' ) + 1 );

    $parts = parse_url($url);

    parse_str($parts['query'], $parameters);

    foreach($parameters as $name => $value) {

        $base_url .= "&" . $name . "=".urlencode($value);

    }

    $url = $base_url;

}

    $options = array(

        CURLOPT_HTTPHEADER => array('Api-key: ' . $this->api_key),  // send API key in header

        CURLOPT_RETURNTRANSFER => true,                             // return web page

        CURLOPT_HEADER         => false,                            // don't return headers

        CURLOPT_FOLLOWLOCATION => true,                             // follow redirects

        CURLOPT_ENCODING       => "",                               // handle all encodings

        CURLOPT_USERAGENT      => "user",                           // who am i

        CURLOPT_AUTOREFERER    => true,                             // set referer on redirect

        CURLOPT_CONNECTTIMEOUT => 120,                              // timeout on connect

        CURLOPT_TIMEOUT        => 120,                              // timeout on response

        CURLOPT_MAXREDIRS      => 10,                               // stop after 10 redirects

        CURLOPT_SSL_VERIFYPEER => false                             // Disabled SSL Cert checks (if enabled, ensure path for CURLOPT_CAINFO is correct)

        //CURLOPT_CAINFO           => "breeze/cacert.pem",          // security certificate

        //CURLOPT_SSLVERSION        => 3                            // set correct SSL version

    );

    // get page data

    $ch      = curl_init( $url );

    curl_setopt_array( $ch, $options );

    $content = curl_exec( $ch );

    $err     = curl_errno( $ch );

    $errmsg  = curl_error( $ch );

    $header  = curl_getinfo( $ch );

    curl_close( $ch );

    // set to variables

    $header['errno']   = $err;

    $header['errmsg']  = $errmsg;

    $header['content'] = $content;

    if(empty($header['content']) || $header['content'] == false) {

        return $header['errmsg'];

    }

    // return content

    return $header['content'];

}

}

?>`

Also here is some is the code in order to call the api index.php 👍

`<?php

require_once('breeze/breeze.php'); $breeze = new Breeze('your_api_key'); $subdomain = 'https://yoursubdomain.breezechms.com/api/';

$people = $breeze->url($subdomain . '/people/');

// get all breeze ids for people updated since 2016-1-25 $summary = $breeze->url($subdomain . '/account/summary');

// List People $list_people = $breeze->url($subdomain . '/people/');

// Show Person $person = $breeze->url($subdomain . '/people/15860394');

// Set to Data Variable $data = $people;

// Add Headers to Response header('Access-Control-Allow-Origin: *'); header('Content-type: application/json; charset=UTF-8'); $myJSON = json_encode(json_decode($data), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

// Json Response echo $myJSON;

?>`

Feel free to use the example code. It should work.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

danbru1989 commented 2 years ago

@StanleyBonhomme Any idea why I'm getting this error in Postman? I've not started messing with actual PHP on our website yet, but Postman is getting stuck on this. What's the issue that you identified?

StanleyBonhomme commented 2 years ago

@danbru1989 Hey what error are you getting specifically? Also if you are not able to see the json api in postman. You might need to run the code via a local web server on your computer. And have you tried the code and example that I have posted above?

cccgit-team commented 2 years ago

@danbru1989 not sure if you got any help but I had the same issue in Postman today. try using "api-key" in the Header and not "Api_Key" or anything else you might have tried.

danbru1989 commented 2 years ago

Sorry, I forgot about this thread. Yes, I figured out the same thing last week. Must use "api-key" as the KEY in the Header and your API key as the VALUE.