# How to set the callback?

**URL:** <https://forum.mautic.org/t/how-to-set-the-callback/3099>\
**Category:** Product Support\
**Created:** [December 30, 2015, 3:46pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099 "2015-12-30T15:46:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [December 30, 2015, 3:46pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/1 "2015-12-30T15:46:11Z")

</div>

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](http://example.com) and mautic is on subdomain (obviously) [http://mautic.example.com](http://mautic.example.com)  
  
  
  
Inside Mautic API credentials I did set the key and token for “[http://example.com](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?

---

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [December 30, 2015, 3:46pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/2 "2015-12-30T15:46:11Z")

</div>

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](http://example.com) and mautic is on subdomain (obviously) [http://mautic.example.com](http://mautic.example.com)

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

```auto
$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?

---

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [December 31, 2015, 3:12pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/3 "2015-12-31T15:12:45Z")

</div>

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:

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

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

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [December 31, 2015, 4:57pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/4 "2015-12-31T16:57:23Z")

</div>

@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](https://github.com/mautic/mautic-wordpress)

---

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [December 31, 2015, 5:33pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/5 "2015-12-31T17:33:19Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [December 31, 2015, 5:38pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/6 "2015-12-31T17:38:49Z")

</div>

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

[https://github.com/mautic/mautic-joomla](https://github.com/mautic/mautic-joomla)

---

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [December 31, 2015, 5:58pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/7 "2015-12-31T17:58:44Z")

</div>

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

```auto
'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:

```auto
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:

```auto
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:

```auto
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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![tasselhof](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tasselhof](https://forum.mautic.org/u/tasselhof)\
**Post date:** [January 1, 2016, 11:23am UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/8 "2016-01-01T11:23:03Z")

</div>

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:

```auto
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)

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:54pm UTC](https://forum.mautic.org/t/how-to-set-the-callback/3099/9 "2020-02-02T22:54:38Z")

</div>


