How to set the callback?

I am getting pesky “Callback is not valid” error message when trying to authorise my wordpress plugin towards my test installation of mautic.



My test wordpress site runs on http://example.com and mautic is on subdomain (obviously) http://mautic.example.com



Inside Mautic API credentials I did set the key and token for “http://example.com” and now I did put it as hardcode to the settings:

Code:
$settings = array( 'baseUrl' => $this->getMauticBaseUrl(), 'version' => $this->mauticOptions['version'], 'clientKey' => $this->mauticOptions['clientKey'], 'clientSecret' => $this->mauticOptions['clientSecret'], 'callback' => "http://example.com/" );

But even this setup gets me "Callback is not valid" error message.

How do I proceed further?

I am getting pesky “Callback is not valid” error message when trying to authorise my wordpress plugin towards my test installation of mautic.

My test wordpress site runs on http://example.com and mautic is on subdomain (obviously) http://mautic.example.com

Inside Mautic API credentials I did set the key and token for “http://example.com” and now I did put it as hardcode to the settings:

$settings = array(
			'baseUrl'		=> $this->getMauticBaseUrl(),
			'version'		=> $this->mauticOptions['version'],
			'clientKey'		=> $this->mauticOptions['clientKey'],
			'clientSecret'	=> $this->mauticOptions['clientSecret'],
			'callback'		=> "http://example.com/"
		);

But even this setup gets me “Callback is not valid” error message.

How do I proceed further?

OK, I am really clueless now. Only requirement I heard here about the callback is, that it has to be the same inside Mautic and inside the calling application. I made sure (triple checked now) that they are the same. Are there any other requirements for callback URI?

Specifically, mine callback URI is set to this:

http://mywii.cz/?edd-listener=mautic

is the part with question mark OK? Where else should I expect errors?

@tasselhof I didn’t know that WP plugin can/need to be authorized. Do you use some special version of the official WP plugin? https://github.com/mautic/mautic-wordpress

@escopecz I am trying to build my own wordpress plugin. Its aim is to integrate Mautic and alternative of Woocommerce. The goal is, that when some customer buys something, they should get propagated into Mautic. For that I need to access Leads API - and for that I need to obtain the token

I tried to implement it to the Joomla plugin so you may take a look in the code:

https://github.com/mautic/mautic-joomla

I did take a look (and reused some code for the plugin). Lets have a look at the callback here. From the Joomla plugin:

'callback'		=> JURI::root() . 'administrator'

Now, in general terms:

  1. Does the callback have to lead directly to the script wich called the authorisation on Mautic?

And, in my case I did actually set it up in a way that the callback redirects to self. From my plugin:

function edd_mautic_listener(){

 if ( isset( $_GET['edd-listener'] ) && $_GET['edd-listener'] == 'mautic' ) {           
        do_action('edd_mautic_pingback');
	}
}
add_action( 'init', 'edd_mautic_listener' );

This piece of code makes sure, that when the ?edd-listener=mautic is added at the end of the URL of wordpress installation, the pingback is going to be processed. The pingback itself calls the authorise function, which is inspired by the Joomla plugin:

function edd_mautic_pingback($reauthorize = false)	{
        
        require(plugin_dir_path(__FILE__) . 'lib/eddToMauticApiHelper.php');	
		
        $apiHelper = new eddToMauticApiHelper();		
		$mauticBaseUrl	= $apiHelper->getMauticBaseUrl();
		$auth			= $apiHelper->getMauticAuth($reauthorize);
		try 
		{
			if ($auth->validateAccessToken())
			{
				if ($auth->accessTokenUpdated())
				{
					$accessTokenData = $auth->getAccessTokenData();
					
                    update_option("mautic_options", $accessTokenData);	
					
				}
				else
				{

					/** do nothing*/
				}
			}
		}
		catch (Exception $e)
		{
		    echo "Exception: " .$e->getMessage();
			exit;
			/*$app->enqueueMessage($e->getMessage(), 'error');
			$this->log($e->getMessage(), JLog::ERROR);*/
		}
		wp_redirect($apiHelper->getCallback());
		
	}

and the piece where I ask for authorisation is above, vbut to be sure, lets repeat that:

public function getMauticAuth($clearAccessToken = false)
	{
		$settings = $this->getApiSettings();

		if ($clearAccessToken)
		{
			unset($settings['accessToken']);
			unset($settings['accessTokenSecret']);
			unset($settings['accessTokenExpires']);
			unset($settings['refreshToken']);
			unset($_SESSION['OAuth1a']);
			unset($_SESSION['OAuth2']);
			unset($_SESSION['oauth']);
		}

		return MauticAuthApiAuth::initiate($settings);
	}

As you can guess, the above is taken from Joomla plugin, I decided to use exactly the same approach.

public function getApiSettings()
	{
		$settings = array(
			'baseUrl'		=> $this->getMauticBaseUrl(),
			'version'		=> $this->mauticOptions['version'],
			'clientKey'		=> $this->mauticOptions['clientKey'],
			'clientSecret'	=> $this->mauticOptions['clientSecret'],
			'callback'		=> "http://mywii.cz/?edd-listener=mautic"
		);

		if (!empty($this->mauticOptions['access_token']))
		{
			$settings['accessToken']		= $this->mauticOptions['access_token'];
			$settings['accessTokenSecret']	= $this->mauticOptions['access_token_secret'];
			$settings['accessTokenExpires']	= $this->mauticOptions['access_token_expires']; 
			//, $this->mauticOptions['expires']);
			$settings['refreshToken']		= $this->mauticOptions['refresh_token'];
		}
		
		

		return $settings;
	}

As you can see, I decided to hardcode the callback now. Triple checked, keypair is correct, and both Mautic installation and my plugin have the http://mywii.cz/?edd-listener=mautic as callback.

Still, I am getting “callback is not valid” error.

Does Mautic have any extra logging options? Somewhere where I could see more reason what went wrong?

SOLVED: After going through the code fot zillionth time, the Joomla approach was what got me down. After removing this line everything started to work:

include_once( '/Mautic/AutoLoader.php');

I am not quite sure if I am storing the token correctly, but will start different thread for that later (after investigating it on my own)