So I was happily programming and testing away, and everything was working and then suddenly I started getting this error:
PHP Fatal error: Uncaught API_Exception: [0]: Authorization failed
thrown in /home/my_public_html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php on line 223
I am writing code in an external php file and using this method to gain access:
require_once '/home/my_public_html/wp-content/plugins/civicrm/civicrm/civicrm.config.php';
require_once '/home/my_public_html/wp-content/plugins/civicrm/civicrm/CRM/Core/Config.php';
$civi_config = CRM_Core_Config::singleton();
I was able to get and create Financial Types as well as get and create Contacts without any issues. But then suddenly started getting the error.
This is one of the calls I am making (which is giving me error):
$financial_type_name = "Donations";
$financialTypes = civicrm_api4('FinancialType', 'get', [
'select' => [
'name',
'id',
'is_deductible',
],
'where' => [
['name', '=', $financial_type_name],
],
]);
print_r($financialTypes);
EDIT: Using @Demerit answer, this is what the proper working call looks like with checkPermissions=FALSE
$financial_type_name = "Donations";
$financialTypes = civicrm_api4('FinancialType', 'get', [
'checkPermissions'=>FALSE,
'select' => [
'name',
'id',
'is_deductible',
],
'where' => [
['name', '=', $financial_type_name],
],
]);
print_r($financialTypes);