REST API is not working

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
ashish915
Posts: 1
Joined: 22 Feb 2019, 06:57

REST API is not working

Post by ashish915 »

Hi,
I am trying to use mantis REST API on mantisBT 2.11

Code: Select all

curl --location --request GET "http://210.212.210.212/helpdesk/api/rest/issues/1"  --header "Authorization: generatedtokenhere"
However When I use this curl, I'm getting 404 error. After checking the mantis folder, I think it is because there is no folder called issues inside helpdesk/api/rest .

And I have also found that there is this file /helpdesk/api/rest/restcore/users_rest.php

But still the following API doesnt work

Code: Select all

curl --location --request GET "http://210.212.210.212/helpdesk/api/rest/restcore/users_rest.php?id=1"  --header "Authorization: generatedtokenhere"
What am I doing wrong?
How can I successfully use REST API to view an issue? any help would be much appreciated.
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: REST API is not working

Post by atrol »

ashish915 wrote: 22 Feb 2019, 07:11 mantis REST API on mantisBT 2.11
There are some REST API related bug fixed since 2.11.
You should upgrade to latest one (2.19.0 at the moment) before any other investigation.
Please use Search before posting and read the Manual
stef-lhm11
Posts: 55
Joined: 28 Aug 2013, 12:32

Re: REST API is not working

Post by stef-lhm11 »

I am on 2.19 and i have the same problems. There is no folder "projects" or "issues" in ...api/rest/...
in the config, the rest api enable is on. are there other things i have to keep in mind?
stef-lhm11
Posts: 55
Joined: 28 Aug 2013, 12:32

Re: REST API is not working

Post by stef-lhm11 »

there is always the 404 error. do i need url rewriting in apache?
stef-lhm11
Posts: 55
Joined: 28 Aug 2013, 12:32

Re: REST API is not working

Post by stef-lhm11 »

but .ht access in api/rest says

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
stef-lhm11
Posts: 55
Joined: 28 Aug 2013, 12:32

Re: REST API is not working

Post by stef-lhm11 »

Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

in .htaccess .../api/rest/ folder is important. Now it works.
stef-lhm11
Posts: 55
Joined: 28 Aug 2013, 12:32

Re: REST API is not working

Post by stef-lhm11 »

it is important that in httpd.conf

<Directory "/.../../.../api/rest">
AllowOverride All
Order allow,deny
Allow from all
</Directory>

is mentioned!
wutsdis
Posts: 4
Joined: 22 Aug 2019, 13:44

Re: REST API is not working

Post by wutsdis »

Hello,

I have a similar problem with the REST API returning an error 404.
The server is on Ubuntu 18.04 with Apache 2.4 and php7.3, mantisBT 2.21.1.

When I test it locally with the same apache, php and mantis versions with XAMPP on windows - it is working without any problems.

I tried a Virtual Machine with Ubuntu and exact same software, again not working and getting an error 404.

I am lost at what to do, I have tried comparing and enabling/disabling some apache modules but nothing has changed.


Edit: After 2 days, I have resolved it.
I have changed the /etc/apache2/apache2.conf settings to:
<Directory /var/www/>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>

Hope that at least it helps someone else, not many active people on this forum.
leonard1980
Posts: 1
Joined: 15 Oct 2019, 10:24

Re: REST API is not working

Post by leonard1980 »

I Have MantisBT 2.22.1 and the REST api is not working. It keeps giving me the "401" error - API token required. I tried With the generated authorization token, like in the documentation, and the same result in Postman and Insomnia. I tried something I fond on the internet: to put on htaccess from the api folder this line "SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0" but nothing happened. So I cannot use this rest api.
Lokesh
Posts: 1
Joined: 03 Dec 2019, 09:33

APIs of the tool are not working

Post by Lokesh »

I am using Mantis2.22.1. I have installed it using bitnami. It is working fine but I am not able to use REST API which are exposed for this tool.
We want to make the use of this API so that we can log the bugs in programmatic way through our application.For this, what I nderstood to use the token and see whether the API is working fine initially or not. I am generating the token from API TOKENS in user option. It is getting not validated when we try to use the API.

I am calling the APIs using postman and I am referring below link

https://documenter.getpostman.com/view/ ... ion=latest


Would appreciate if anyone can help on this or provide any pointers. This is bit critical as per our delivery schedule and hence urgent. Thanks in advance.
mnewnham
Posts: 1
Joined: 06 Dec 2019, 16:12

Re: REST API is not working

Post by mnewnham »

HTH for all trying to get this working

My server is Apache2.2
The first error I got was

Code: Select all

/mantisbt/api/rest/issues was not found 404
To resolve this, I changed the conf.d/mantisbt.conf from

Code: Select all

AllowOverride None
to

Code: Select all

AllowOverride All
Once I changed that, I got an Error 500. Looking in the log, I saw

Code: Select all

configuration error:  couldn't perform authentication. AuthType not set!: /mantisbt/api/rest/issues
That was because I had a configuration item

Code: Select all

Require all granted
In my mantisbt.conf. This command isn't valid in apache2.2, only 2.4. My final mantisbt.conf file looks like this, very simple

Code: Select all

Alias /mantisbt "/home/mantisbt/mantisbt"
<Directory "/home/mantisbt/mantisbt">
AllowOverride All
</Directory>
The next problem was when I tried to issue a request against the API. I got an error:

Code: Select all

<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /home/mantisbt/mantisbt-2.22.1/api/rest/index.php was not found on this server.</p>
<hr>
Note that although the rewrite rule is finding index.php, I'ts looking in the wrong directory. The problem is caused because mantis
isn't installed under /var/www/html. To fix it, I simply hardcoded the full path to index.php in the rule.

Here is my .htaccess file in /mantisbt/api/rest

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /mantisbt/api/rest/index.php [QSA,L]
I can now issue rest requests against mantis
Post Reply