Mautic Community Forums

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

@naomicbush thank you. That solved my problem too.