Mautic API Error: Requested URL not found

Hey,



I have a little problem:



Situation: I want to call the Mautic API and get a response, which isn’t an error.



I use the API library (https://github.com/mautic/api-library).

The API is enabled in the configuration settings and I have authorized my requests with oAuth1a.

Everything’s working fine with the authorization.



Mautic is installed in the subdirectory ‘mautic’.



Whenever I make a call to the API I get the response, that the requested URL has not been found:



The $json_response of the following code is:



{“contact”:{“error”:{“message”:“Requested URL not found: /mautic/api/contacts/new”,“code”:404}}}



So /mautic/api/contacts/new has not been found. This happens with every endpoint!

Even when I use the API Tester exactly the same happens.

Code:
<?php

include DIR . ‘/vendor/autoload.php’;

use MauticAuthApiAuth;
use MauticMauticApi;

$settings = array(
‘baseUrl’ => ‘http://mysite.com/mautic’,
‘version’ => ‘OAuth1a’,
‘clientKey’ => ‘xxxxxxxxxxxxxxx’,
‘clientSecret’ => ‘xxxxxxxxxxxxxxx’,
‘callback’ => ‘http://mysite.com/go.php’, // used before to get access tokens (see below)
‘accessToken’ => ‘xxxxxxxxxxxxxxx’, // <-- hard coded access token data
‘accessTokenSecret’ => ‘xxxxxxxxxxxxxxx’ // <-- hard coded access token data
);

$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = “http://mysite.com/mautic”;
$api = new MauticApi();

$contactApi = $api->newApi(“contacts”, $auth, $apiUrl);

$data = array(
‘firstname’ => ‘Jim’,
‘lastname’ => ‘Contact’,
‘email’ => ‘jim@his-site.com’,
‘ipAddress’ => $_SERVER[‘REMOTE_ADDR’]
);

$contact = $contactApi->create($data);

$json_response[‘contact’] = $contact;

header(‘Content-Type: application/json’);
echo json_encode($json_response);




Does anybody know a solution for that?

Thanks a lot!

Hey,

I have a little problem:

Situation: I want to call the Mautic API and get a response, which isn’t an error.

I use the API library (https://github.com/mautic/api-library).
The API is enabled in the configuration settings and I have authorized my requests with oAuth1a.
Everything’s working fine with the authorization.

Mautic is installed in the subdirectory ‘mautic’.

Whenever I make a call to the API I get the response, that the requested URL has not been found:

The $json_response of the following code is:

{“contact”:{“error”:{“message”:“Requested URL not found: /mautic/api/contacts/new”,“code”:404}}}

So /mautic/api/contacts/new has not been found. This happens with every endpoint!
Even when I use the API Tester exactly the same happens.


<?php

include __DIR__ . '/vendor/autoload.php';

use MauticAuthApiAuth;
use MauticMauticApi;


$settings = array(
    'baseUrl'           => 'http://mysite.com/mautic',  
    'version'           => 'OAuth1a', 
    'clientKey'         => 'xxxxxxxxxxxxxxx', 
    'clientSecret'      => 'xxxxxxxxxxxxxxx',     
    'callback'          => 'http://mysite.com/go.php', // used before to get access tokens (see below)
    'accessToken'       => 'xxxxxxxxxxxxxxx', // <-- hard coded access token data
    'accessTokenSecret' => 'xxxxxxxxxxxxxxx' // <-- hard coded access token data
);


$initAuth   = new ApiAuth();
$auth       = $initAuth->newAuth($settings);
$apiUrl     = "http://mysite.com/mautic";
$api        = new MauticApi();


$contactApi = $api->newApi("contacts", $auth, $apiUrl);


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


$contact = $contactApi->create($data);


$json_response['contact'] = $contact;

header('Content-Type: application/json');
echo json_encode($json_response);

Does anybody know a solution for that?

Thanks a lot!

Same problem…
Any hint on this issue?

@rauljimenez it’s been solved many times :slight_smile: clear your cache

https://www.mautic.org/community/index.php/6801-help-thriveleads-api-is-not-populating-contact-segments-list

https://wordpress.org/support/topic/oauth-1-add-new-blank-page-oauth-2-404-error/

https://www.mautic.org/community/index.php/6583-api-call-returns-404/p1#p18700

https://www.mautic.org/community/index.php/6687-mautic-api-error-requested-url-not-found/p1#p19115

Slack:

Here’s the correct way to do it:

https://mautic.org/docs/en/tips/troubleshooting.html

1 Like

@naomicbush thank you. That solved my problem too.

Running the command mentioned above didn’t fix the problem for me, but I fixed it 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)

1 Like

If / when this blows up someone’s setup… try the advice here to check that your site setting in the local.php file is prefixed correctly (http or https) to match whatever load-balancer / redirection scheme you have.

I am trying to add a new contact from pabbly to mautic, I get this error

Requested URL not found: //api/contacts/new
404.

I have cleared cache but still doesnt work please assist

  1. php /var/www/html/mautic/bin/console cache:clear
  2. rm -rf var/cache/*

Mautic 4.4.8

I have done some reading and noted that there is someone who said another issue is the double slashes.

my url has double slashes. kindly let me know where I can remove the double slashes in mautic

my error:
Requested URL not found: //api/contacts/new
404.


Hi, you can remove it here:
Gear icon > Configuration > System settings > Site URL : remove the trainling slash from the end of your URL

Hi,

I confirm that this is well set as per your instructions

Gear icon > Configuration > System settings > Site url
https://mautic.domain.com

**** ERROR ***
However, I still get the double slash error

my error:
Requested URL not found: //api/contacts/new
404.

How does your call look like?
Maybe you are still calling at yourcomain.com//api … ?

the base url is well set without / slash at the end…

Otherwise I decided to delete connection and do a fresh one. Unfortunately I have digressed! as now connection wont work after clearing cache and also Enabling API and HTTP basic auth

Is it installed in a subdirectory … es with the initial post?
Don’t forget to adjust the provided .htaccess - as this only works with Mautic in root folders of the webserver document directory. If Mautic runs on TLD/mautic/ or similar, .htaccess needs an edit after each update.

hi.

I create my mautic. in a subdomain http://mautic.domain.com however, the actual directory is
/public_html/mautic

kindly could you give actual code I can add to .htacess

I appreciate this!!!

If the Mautic is available at the root of your subdomain, the .htaccess is not your problem.

So the dashboard appears at http://mautic.domain.com/s/dashboard - not http://mautic.domain.com/mautic/s/dashboard?

Then this issue can be ignored, doesn’t apply to you.

Question: you did enable Mautic API first, right? Its disabled by default.

(P.S. hope you mean https, not http :P)