Top Menu

Jump to content
Home
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Calendars
    Calendars
  • Team planners
    Team planners
  • Boards
    Boards
  • News
  • Forums

Content

Development
  1. OpenProject
  2. Forums
  3. Development
  4. PHP login failing - 401 error

PHP login failing - 401 error

Added by James Neale almost 2 years ago

I'm attempting to build a PHP app in Lavarel to read a listing of my Work Packages . 
I run a self hosted instance of OpenProject 12.5.4, and can read my packages as json using a curl command below

curl -u apikey:my_api_key http://my-server/openproject/api/v3/work_packages

but if I try this function in PHP below, it returns a '401 Unauthorized' response error, and I cannot figure out why.

private function fetchTasks()
{
    $client = new Client();
    $apiKey = 'my_api_key';
    $url = 'http://my-server/openproject/api/v3/work_packages';

    $response = $client->request('GET', $url, [
        'headers' => [
            'Authorization' => 'Basic ' . base64_encode($apiKey . ':'),
            'X-Requested-With' => 'XMLHttpRequest',
        ],
    ]);

    return json_decode($response->getBody(), true);
}

Can anyone assist please?


Replies (1)

RE: PHP login failing - 401 error - Added by James Neale almost 2 years ago

I figured it out from the documentation
I needed to put username "apikey" followed by my_api_key
like this

private function fetchTasks()
{
    $client = new Client();
    $apiKey = 'my_api_key';
    $url = 'http://my-server/openproject/api/v3/work_packages';

    $response = $client->request('GET', $url, [
        'auth' => ['apikey', 'my_api_key'],
        'headers' => [
            'X-Requested-With' => 'XMLHttpRequest',
        ],
    ]);

    return json_decode($response->getBody(), true);
}
  • (1 - 1/1)
Loading...