# API call returns 404

**URL:** https://forum.mautic.org/t/api-call-returns-404/7098
**Category:** Product Support
**Created:** [January 9, 2017, 8:20pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098 "2017-01-09T20:20:41Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 9, 2017, 8:20pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/1 "2017-01-09T20:20:41Z")

</div>

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!! ![=)]( "=)")

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 9, 2017, 8:20pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/2 "2017-01-09T20:20:41Z")

</div>

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

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

Can anyone help-me with this issue?

Thanks!! =)

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 9, 2017, 9:17pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/3 "2017-01-09T21:17:29Z")

</div>

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):

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

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 1:10am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/4 "2017-01-10T01:10:34Z")

</div>

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

My URL under configuration: [http://localhost/mautic](http://localhost/mautic)

The error is:

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 1:55am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/5 "2017-01-10T01:55:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 2:35am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/6 "2017-01-10T02:35:01Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 2:50am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/7 "2017-01-10T02:50:18Z")

</div>

Yes!

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 3:29am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/8 "2017-01-10T03:29:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 3:38am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/9 "2017-01-10T03:38:43Z")

</div>

@MxyzptlkFishStix yes!  
blank, [http://localhost:8000/](http://localhost:8000/) and [http://localhost:8000](http://localhost:8000)

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

---

<div class="post-metadata">

### Author: ![lucianojmf](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/lucianojmf/32/5441_2.png) [@lucianojmf](https://forum.mautic.org/u/lucianojmf)
#### Post date: [January 10, 2017, 4:22am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/10 "2017-01-10T04:22:30Z")

</div>

Woooow!!! Its works!! 🙂

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

Thanks @MxyzptlkFishStix !

---

<div class="post-metadata">

### Author: ![kleinpeter](https://avatars.discourse-cdn.com/v4/letter/k/ac91a4/32.png) [@kleinpeter](https://forum.mautic.org/u/kleinpeter)
#### Post date: [January 18, 2017, 12:01am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/11 "2017-01-18T00:01:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mingfang](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mingfang](https://forum.mautic.org/u/mingfang)
#### Post date: [January 26, 2017, 2:28am UTC](https://forum.mautic.org/t/api-call-returns-404/7098/12 "2017-01-26T02:28:38Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![diegov](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/diegov/32/196_2.png) [@diegov](https://forum.mautic.org/u/diegov)
#### Post date: [June 13, 2017, 5:17pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/13 "2017-06-13T17:17:37Z")

</div>

+1  
Also waste some hours on this… 😕

---

<div class="post-metadata">

### Author: ![process.env](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/process.env/32/1097_2.png) [@process.env](https://forum.mautic.org/u/process.env)
#### Post date: [October 15, 2020, 7:19pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/14 "2020-10-15T19:19:32Z")

</div>

I fixed this by running the clear:cache command from Mautic, the command will look something like:  
`php /var/www/html/mautic/bin/console cache:clear`  
(_change the path to your Mautic installation - and **if you have a pre-3 version** , it will be “`app/console`” for you instead of “`bin`”_)

(PD: If you get some “can’t locate php” error, change the “`php`” part of the code by the path you have in your crons pointing to php (to find it, write “`crontab -e`” or “`sudo crontab -e`” on the command line and copy the string/path between “-c” and “-q” _(which in my case is “/opt/bitnami/php/bin/php” since I installed it through Bitnami)_

---

<div class="post-metadata">

### Author: ![aerendir](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/aerendir/32/1050_2.png) [@aerendir](https://forum.mautic.org/u/aerendir)
#### Post date: [February 17, 2022, 12:16pm UTC](https://forum.mautic.org/t/api-call-returns-404/7098/15 "2022-02-17T12:16:37Z")

</div>

Sometimes the error is the HTTP method used.

For example, if you call `api/contacts/new` using a `GET`HTTP method, then you will get a 404 error.  
If you, instead, use the `POST` HTTP method, then the API works.
