AnsweredAssumed Answered

Web Request - referencing certificates

Question asked by ducmac on May 7, 2018

Hi, 

 

I'm trying to connect to Xero api with nintex workflow but am having no luck at all.I have some working code that allows me to communicate with Xero via PHP. 

 

HERE is the code:

----------------------START CODE--------------------------

<?php
require 'lib/XeroOAuth.php';

define ( 'BASE_PATH', dirname(__FILE__) );
define ( "XRO_APP_TYPE", "Private" );
define ( "OAUTH_CALLBACK", "oob" );
$useragent = "Demo";

$signatures = array (
'consumer_key' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234',
'shared_secret' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234',
// API versions
'core_version' => '2.0',
'payroll_version' => '1.0',
'file_version' => '1.0'
);

if (XRO_APP_TYPE == "Private" || XRO_APP_TYPE == "Partner") {
$signatures ['rsa_private_key'] = BASE_PATH . '/certs/privatekey.pem';
$signatures ['rsa_public_key'] = BASE_PATH . '/certs/publickey.cer';
}

$XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
include 'tests/testRunner.php';

$initialCheck = $XeroOAuth->diagnostics ();
$checkErrors = count ( $initialCheck );
if ($checkErrors > 0) {
// you could handle any config errors here, or keep on truckin if you like to live dangerously
foreach ( $initialCheck as $check ) {
echo 'Error: ' . $check . PHP_EOL;
}
} else {
$session = persistSession ( array (
'oauth_token' => $XeroOAuth->config ['consumer_key'],
'oauth_token_secret' => $XeroOAuth->config ['shared_secret'],
'oauth_session_handle' => ''
) );
$oauthSession = retrieveSession ();

if (isset ( $oauthSession ['oauth_token'] )) {
$XeroOAuth->config ['access_token'] = $oauthSession ['oauth_token'];
$XeroOAuth->config ['access_token_secret'] = $oauthSession ['oauth_token_secret'];

include 'tests/tests.php';
}

testLinks ();
}

 ---------------------------END OF CODE--------------------------

 

In the PHP code, I reference two files for me to connect to the API, the public key certificate and the private key PEM. Am i able to reference these files in the web request?
Does anyone know how to connect with a private application using nintex? 

Outcomes