Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect with Mautic API #99

Closed
aravintha opened this issue Mar 21, 2017 · 3 comments
Closed

Not able to connect with Mautic API #99

aravintha opened this issue Mar 21, 2017 · 3 comments

Comments

@aravintha
Copy link

Hi,

I am trying to connect Mautic API through this pluging, Download this plugin and install composer. Then create a new file in apitester (base.php).

base.php (source code):

`

     include '../vendor/autoload.php';
 require_once '../lib/MauticApi.php';
 use Mautic\Auth\ApiAuth;
 use Mautic\MauticApi;
     $apiUrl = "http://localhost/mautic/index.php";

 $settings = array(
     'AuthMethod'       => 'BasicAuth', 
     'userName'         => 'admin',
     'password'         => 'Admin123!',        
     'apiUrl'           => 'http://localhost/mautic/index.php',         
 );


try {
	// Initiate the auth object specifying to use BasicAuth
	$initAuth = new ApiAuth();
	$auth = $initAuth->newAuth($settings, 'BasicAuth');

	if ($auth) {
		
		$api = new MauticApi();
		$contactApi = $api->newApi('contacts', $auth, $apiUrl);
		
		// Get Contact list
		$results = $contactApi->getList();
		var_dump($results);
	} else {
		echo "Something went wrong!";
	}
} catch (Exception $e) {
	echo "Mautic not connected!";	
}`

But this one always throw an error like:

'errors' =>
array (size=1)
0 =>
array (size=3)
'message' => string 'Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC' (length=70)
'code' => int 404
'type' => null
'error' =>
array (size=2)
'message' => string 'Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC (error is deprecated as of 2.6.0 and will be removed in 3.0. Use the errors array instead.)' (length=166)
'code' => int 404

@escopecz
Copy link
Sponsor Member

2 thoughts:

  1. If your Mautic needs the /index.php/ part in the URL to run, then your .htaccess or mod_rewrite or virtual host config is not correct.
  2. Did you try to clear Mautic's cache? https://mautic.org/docs/en/tips/troubleshooting.html

@aravintha
Copy link
Author

aravintha commented Mar 21, 2017

Hi Escopcz,

Thanks for your reply,
Cleared the cache from mautic folder.

This is my .htaccess file what can I do here to change the virtual host
`

 <IfModule mod_rewrite.c>
RewriteEngine On


RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]


RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]


RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]


RewriteRule .? %{ENV:BASE}/index.php [L]
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
 RedirectMatch 302 ^(?!/(index\.php|index_dev\.php|app|addons|plugins|media|upgrade))(/(.*))$ /index.php$2
    
</IfModule>
</IfModule>
<IfModule mod_php5.c> 
php_value always_populate_raw_post_data -1

`

@escopecz
Copy link
Sponsor Member

That's a server configuration. Try to find some tutorial which fits your server. For example https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants