Project

General

Profile

Using cURL to access the API

Added by Harry Lime 19 days ago

I have a working install of 5.1.0, but I now need to access the API, from the server where Redmine is installed.

To do this, I'm stopping Apache, and then directly starting Passenger as 'passenger start'. I'm then trying to get a page with cURL:

 $ curl http://127.0.0.1:3000/

This doesn't return the front page - the 'passenger start' output just says "//public/index.html is not found". Redmine is installed at /opt/redmine-5.1.0, so I've also tried:

 $ curl http://127.0.0.1:3000/opt/redmine-5.1.0
 $ curl http://127.0.0.1:3000/opt/redmine-5.1.0/
 $ curl http://127.0.0.1:3000/opt/redmine-5.1.0/public/

But these don't work either, returning

"//public/opt/redmine-5.1.0" failed (2: No such file or directory)
"//public/opt/redmine-5.1.0/index.html" is not found (2: No such file or directory)
"//public/opt/redmine-5.1.0/public/index.html" is not found (2: No such file or directory)

Can anyone tell me what URL I should use to get, for example, the admin user's details? Where does the '//public' come from?


Replies (1)

RE: Using cURL to access the API - Added by Ruth Dunlap 5 days ago

It seems Passenger Standalone is not correctly configured to serve your Redmine application located at `/opt/redmine-5.1.0`. The error message "//public/index.html is not found" and the subsequent failures indicate that Passenger is looking for the webroot within its default context, and not within your Redmine installation directory.

Here's a breakdown of why this is happening and how to likely resolve it:

Understanding the Issue:

  • Passenger Standalone's Default Behavior: When you run passenger start without specific configuration, it often assumes the current directory is the web application's root. It then expects a public subdirectory containing the web server's accessible files (like index.html).
  • Redmine's Directory Structure: Redmine's web-accessible files are located within its public subdirectory inside the main Redmine installation directory (/opt/redmine-5.1.0/public).
  • Passenger's Misinterpretation: Passenger Standalone, in your case, seems to be treating the current working directory (where you ran passenger start) as the root and then appending /public to it, leading to it looking for files in a non-existent location like //public/opt/redmine-5.1.0/public/index.html.

How to Correctly Access Redmine via Passenger Standalone:

You need to tell Passenger Standalone where your Redmine application's public directory is located. You can do this using the --root option when starting Passenger.

Correct Command to Start Passenger:

Navigate to the root directory of your Redmine installation (/opt/redmine-5.1.0) and then run:

cd /opt/redmine-5.1.0
passenger start --address 127.0.0.1 --port 3000 --root public

Explanation of the Options:

  • --address 127.0.0.1: Specifies the IP address to listen on (localhost).
  • --port 3000: Specifies the port to listen on.
  • --root public: This is the crucial part. It tells Passenger that the web application's root directory is the `public` subdirectory within the current directory (/opt/redmine-5.1.0/public).

Accessing Redmine After Starting Passenger Correctly:

Once you've started Passenger with the --root public option, you should be able to access your Redmine instance using the base URL:

curl http://127.0.0.1:3000/

This should now return your Redmine front page.

Accessing the API (Admin User Details Example):

To access the admin user's details via the API, you'll need:

1. Enable the REST API: Ensure that the REST API is enabled in your Redmine settings (Administration -> Settings -> API).
2. An API Key: You'll need an API key for authentication. You can find or generate an API key for a user (including the admin user) by going to their user page in Redmine and looking for the "API key" section (usually on the right sidebar).

Assuming you have the admin user's API key (let's say it's YOUR_ADMIN_API_KEY), the URL to fetch their details would be:

curl -H "X-Redmine-API-Key: YOUR_ADMIN_API_KEY" http://127.0.0.1:3000/users/admin.json

Explanation of the API URL:

  • `/users/admin.json`: This is the API endpoint to retrieve information about a specific user. "admin" is the login of the admin user, and .json specifies the desired response format (JSON).

Important Considerations:

  • Environment: Ensure that your Redmine environment is properly configured (database connection, etc.). Passenger Standalone will use the same environment as your regular Redmine setup.
  • Firewall: If you encounter connection issues, make sure that your firewall isn't blocking connections to port 3000 on 127.0.0.1.
  • Production Environment: While Passenger Standalone is useful for testing and development, it's generally recommended to use a production-ready web server like Apache or Nginx with Passenger for a live Redmine instance.

By correctly specifying the --root option when starting Passenger Standalone, you should be able to access your Redmine application and its API from the server. Remember to replace YOUR_ADMIN_API_KEY with the actual API key of your admin user.

    (1-1/1)