Mautic Community Forums

API call returns 404

Hi guys,

I have started with Mautic in few days ago using a localhost test server (apache2).

So, i’m trying integrate it with my current platform using REST API.



Every call to consume any endpoint results in a 404 return. The API is using OAuth1 and was succesfully autenticated.



On example bellow i’m trying create a new contact. (i tried get, getList, and others endpoints too… all with same result 404)



DebugInfo:

Code:
'flow' => array ( '01-09 20:06:33' => array ( 0 => 'validateAccessToken()', 1 => 'has access token', 2 => 'makeRequest(http://localhost/mautic/index.php/api/contacts/new, firstname=Jim&lastname=Contact&email=jim%40his-site.com&ipAddress=192.168.0.1, POST,...)', 3 => 'making request using OAuth1.0a spec', 4 => 'Posted parameters = firstname=Jim&lastname=Contact&email=jim%40his-site.com&ipAddress=192.168.0.1', ), ), 'basestring' => 'POST&http%3A%2F%2Flocalhost%2Fmautic%2Findex.php%2Fapi%2Fcontacts%2Fnew&email%3Djim%2540his-site.com%26firstname%3DJim%26ipAddress%3D192.168.0.1%26lastname%3DContact%26oauth_consumer_key%3Dro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo%26oauth_nonce%3D3e4c79219e1491fc%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1483992393%26oauth_token%3D1srqh05ega5ccw4kk8w04w44kwccw88gcgo8s8oo8ggo8o4go0%26oauth_version%3D1.0', 'headers' => array ( 'oauth_consumer_key' => 'ro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo', 'oauth_nonce' => '3e4c79219e1491fc', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => 1483992393, 'oauth_version' => '1.0', 'oauth_token' => '1srqh05ega5ccw4kk8w04w44kwccw88gcgo8s8oo8ggo8o4go0', 'firstname' => 'Jim', 'lastname' => 'Contact', 'email' => 'jim@his-site.com', 'ipAddress' => '192.168.0.1', 'oauth_signature' => 'EeWujMwzEjgyWbv1ZeWZNl4ugq8=', ), 'info' => array ( 'url' => 'http://localhost/mautic/index.php/api/contacts/new', 'content_type' => 'application/json', 'http_code' => 200, 'header_size' => 256, 'request_size' => 624, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 0.119952, 'namelookup_time' => 0.0041310000000000001, 'connect_time' => 0.0041739999999999998, 'pretransfer_time' => 0.0042050000000000004, 'size_upload' => 77, 'size_download' => 99, 'speed_download' => 825, 'speed_upload' => 641, 'download_content_length' => 99, 'upload_content_length' => 77, 'starttransfer_time' => 0.119934, 'redirect_time' => 0, 'redirect_url' => '', 'primary_ip' => '::1', 'certinfo' => array ( ), 'primary_port' => 80, 'local_ip' => '::1', 'local_port' => 54679, ), 'returnedHeaders' => 'HTTP/1.1 200 OK Date: Mon, 09 Jan 2017 20:06:33 GMT Server: Apache/2.4.10 (Debian) Set-Cookie: fb383c994053a92e79536ebaf21cb996=7504g4btrccn5ac9iilsssrll7; path=/; HttpOnly Cache-Control: no-cache Content-Length: 99 Content-Type: application/json', 'returnedBody' => '{"error":{"message":"Requested URL not found: \/mautic\/index.php\/api\/contacts\/new","code":404}}',

Error
Code:
'error' => array ( 'message' => 'Requested URL not found: /mautic/index.php/api/contacts/new', 'code' => 404, )


Can anyone help-me with this issue?

Thanks!! =)

Hi guys,
I have started with Mautic in few days ago using a localhost test server (apache2).
So, i’m trying integrate it with my current platform using REST API.

Every call to consume any endpoint results in a 404 return. The API is using OAuth1 and was succesfully autenticated.

On example bellow i’m trying create a new contact. (i tried get, getList, and others endpoints too… all with same result 404)

DebugInfo:

'flow' => array ( '01-09 20:06:33' => array ( 0 => 'validateAccessToken()', 1 => 'has access token', 2 => 'makeRequest(http://localhost/mautic/index.php/api/contacts/new, firstname=Jim&lastname=Contact&email=jim%40his-site.com&ipAddress=192.168.0.1, POST,...)', 3 => 'making request using OAuth1.0a spec', 4 => 'Posted parameters = firstname=Jim&lastname=Contact&email=jim%40his-site.com&ipAddress=192.168.0.1', ), ), 'basestring' => 'POST&http%3A%2F%2Flocalhost%2Fmautic%2Findex.php%2Fapi%2Fcontacts%2Fnew&email%3Djim%2540his-site.com%26firstname%3DJim%26ipAddress%3D192.168.0.1%26lastname%3DContact%26oauth_consumer_key%3Dro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo%26oauth_nonce%3D3e4c79219e1491fc%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1483992393%26oauth_token%3D1srqh05ega5ccw4kk8w04w44kwccw88gcgo8s8oo8ggo8o4go0%26oauth_version%3D1.0', 'headers' => array ( 'oauth_consumer_key' => 'ro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo', 'oauth_nonce' => '3e4c79219e1491fc', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => 1483992393, 'oauth_version' => '1.0', 'oauth_token' => '1srqh05ega5ccw4kk8w04w44kwccw88gcgo8s8oo8ggo8o4go0', 'firstname' => 'Jim', 'lastname' => 'Contact', 'email' => 'jim@his-site.com', 'ipAddress' => '192.168.0.1', 'oauth_signature' => 'EeWujMwzEjgyWbv1ZeWZNl4ugq8=', ), 'info' => array ( 'url' => 'http://localhost/mautic/index.php/api/contacts/new', 'content_type' => 'application/json', 'http_code' => 200, 'header_size' => 256, 'request_size' => 624, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 0.119952, 'namelookup_time' => 0.0041310000000000001, 'connect_time' => 0.0041739999999999998, 'pretransfer_time' => 0.0042050000000000004, 'size_upload' => 77, 'size_download' => 99, 'speed_download' => 825, 'speed_upload' => 641, 'download_content_length' => 99, 'upload_content_length' => 77, 'starttransfer_time' => 0.119934, 'redirect_time' => 0, 'redirect_url' => '', 'primary_ip' => '::1', 'certinfo' => array ( ), 'primary_port' => 80, 'local_ip' => '::1', 'local_port' => 54679, ), 'returnedHeaders' => 'HTTP/1.1 200 OK Date: Mon, 09 Jan 2017 20:06:33 GMT Server: Apache/2.4.10 (Debian) Set-Cookie: fb383c994053a92e79536ebaf21cb996=7504g4btrccn5ac9iilsssrll7; path=/; HttpOnly Cache-Control: no-cache Content-Length: 99 Content-Type: application/json', 'returnedBody' => '{"error":{"message":"Requested URL not found: \/mautic\/index.php\/api\/contacts\/new","code":404}}',

Error

'error' => 
  array (
    'message' => 'Requested URL not found: /mautic/index.php/api/contacts/new',
    'code' => 404,
  )

Can anyone help-me with this issue?

Thanks!! =)

Hi @MxyzptlkFishStix , thanks for reply!

I don’t know if this is really a bug, or just a configuration/trick missed. Probably im doing some thing wrong.

This is my auth code (reminding this is a test environment):

public static function mauticAuth(){

                //object that persist auth informations on database
		$mautic_auth = MauticToken::find(2);

               //verify if a token was generated before
		if($mautic_auth){
			$settings = array(
			    'baseUrl'          => $mautic_auth->url, 
			    'version'          => $mautic_auth->type,
			    'clientKey'        => $mautic_auth->public_key,
			    'clientSecret'     => $mautic_auth->secret,
			    'callback'         => 'http://localhost:8000/',
			    'accessToken' => $mautic_auth->access_token,
			    'accessTokenSecret' => $mautic_auth->access_token_secret
			);
		}else{
			$settings = array(
			    'baseUrl'          => "http://localhost/mautic/index.php",
			    'version'          => "OAuth1a",
			    'clientKey'        => "ro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo",
			    'clientSecret'     => "3swp5ph9owows44w48s48gg80448gs80cgskw0okcw4gw8k0ow",
			    'callback'         => 'http://localhost:8000/',
			);
		}

		// Initiate the auth object
		$initAuth = new ApiAuth();
		$auth = $initAuth->newAuth($settings);

		$auth->enableDebugMode();

		try {
		    if ($auth->validateAccessToken()) {
                       //if firstest login, save configurations on database
		    	if(!$mautic_auth){
		    		$mautic_auth = new MauticToken();

		    		$accessTokenData = $auth->getAccessTokenData();
		    		$mautic_auth->url = 'http://localhost/mautic/index.php';
		    		$mautic_auth->type = 'OAuth1a';
		    		$mautic_auth->public_key = 'ro3dbmru7v4c80wwg08cw4okggkc4ocsgscw0gwockc0000wo';
		    		$mautic_auth->secret = '3swp5ph9owows44w48s48gg80448gs80cgskw0okcw4gw8k0ow';
		                $mautic_auth->access_token = $accessTokenData['access_token'];
		                $mautic_auth->access_token_secret = $accessTokenData['access_token_secret'];
    		                $mautic_auth->expires = $accessTokenData['expires'];
		                $mautic_auth->save();

		    	}

		        if ($auth->accessTokenUpdated()) {
		            $accessTokenData = $auth->getAccessTokenData();
		            $mautic_auth->access_token = $accessTokenData['access_token'];
		            $mautic_auth->access_token_secret = $accessTokenData['access_token_secret'];
		            $mautic_auth->expires = $accessTokenData['expires'];
		            $mautic_auth->save();
		        }
			    return $auth;

		    }else{
		    	return false;
		    }

		} catch (Exception $e) {
		    Log::info($e);
		    return false;
		}
		
	}

And after called auth method, i have made an example function to test a endpoint:

public static function mauticTest($auth){
		$api = new MauticApi();
		$mautic_auth = MauticToken::find(2);


		$data = array(
		    'firstname' => 'Jim',
		    'lastname'  => 'Contact',
		    'email'     => 'jim@his-site.com',
		    'ipAddress' => '192.168.0.1'
		);

		
		$contactApi = $api->newApi('contacts', $auth, $mautic_auth->url);
		$contact = $contactApi->create($data);

		Log::info($auth->getDebugInfo());
	}

Im using Laravel 4.2, mautic/api-library 2.4 and guzzlehttp/guzzle 5.0

Thanks!!

Yes! on dev mode all running on the same machine.

My URL under configuration: http://localhost/mautic

The error is:

 array (
    'message' => 'Requested URL not found: /mautic/api/contacts/new',
    'code' => 404,
  ),

Initially(on first post) mod_rewrite wasn’t working properly, but now all redirects and rewrites works fine.
Even after configuring on apache2, the error still remains the same for API callbacks, i.e “/mautic/api/…” 404

Yes, on dev mode i’m working in a Desktop.
http://localhost/mautic/api is accessible from browser and return:

{"error":"access_denied","error_description":"OAuth2 authentication required"}

Yes!

I have tested with a URL from my app and blank, both have same error.

@MxyzptlkFishStix yes!
blank, http://localhost:8000/ and http://localhost:8000

Strange that I can authenticate successfully, however when an API call happens, a 404 error is thrown… :S

Woooow!!! Its works!! :slight_smile:

After I removed a cache folder from Mautic, everything worked perfectly!

Thanks @MxyzptlkFishStix !

Clear cache works. Don’t worry to delete files in cache folder.
I worried to delete all files in cache folder (app/cache), so I tried to backup over “cp -R cache/ cache_bck” and then I deleted all files in cache folder and it works!
Thank you very much. I spent about 3 hours on it

I wasted 2 days troubleshooting this problem and removing the cache fixes my problem too.

Cache someone explain why removing the cache magically fixes this problem?
Does that mean there is a cache corruption bug within Mautic that needs to be looked at?

+1
Also waste some hours on this… :confused: