Skip Navigation
Expand
  • Advanced SearchOpens new dialog
    Enter plus (+) or minus (-) signs in search terms to make a word required or excluded
    Search Tips
    Filter by product
    Filter by category
PHP load_curl function is failing when using initConnectAPI for API authentication
Answer ID 12924   |   Last Review Date 11/08/2024

Why does using PHP load_curl fail with a 500 error when using initConnectAPI for API authentication?

Environment:

Connect for PHP API (CPHP)
Oracle B2C Service

Issue:

I am developing a PHP Custom/File Manager script and, although the following works for general API authentication, I am receiving an error when trying to use PHP curl (load_curl function specifically). I am aware that API authentication is required for the use of PHP curl with B2C Service. So why is this not working and how do I fix it?
 
My code is as follows:
 

require_once ( get_cfg_var( 'doc_root' ) . '/include/ConnectPHP/Connect_init.phph' );
initConnectAPI([username], [password]);

use RightNow\Connect\v1_4 as RNCPHP;

load_curl();

 

Resolution:

When using initConnectAPI for API authentication, you will need to add the following line of code to use PHP curl/load_curl function:
 

require_once(get_cfg_var( 'doc_root' ) . '/include/init.phph');
require_once ( get_cfg_var( 'doc_root' ) . '/include/ConnectPHP/Connect_init.phph' );
initConnectAPI([username], [password]);

use RightNow\Connect\v1_4 as RNCPHP;

load_curl();

 
The other option is to use AgentAuthenticator for API authentication instead, which is the more-current and recommended method in most cases. Coded for this would be as follows:
 

require_once ( get_cfg_var( 'doc_root' ) . '/include/services/AgentAuthenticator.phph');
$account = AgentAuthenticator::authenticateCredentials([username], [password]);

use RightNow\Connect\v1_4 as RNCPHP;

load_curl();

 
For further details see the API documentation.