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)
I figured it out from the documentation
I needed to put username "apikey" followed by my_api_key
like this