akeneo / Dockerfiles

DEPRECATED for PIM 4.0 and above - Official Dockerfiles for Akeneo development and testing
https://hub.docker.com/r/akeneo/
MIT License
49 stars 34 forks source link

Access the rest API #126

Closed Erwyn closed 7 years ago

Erwyn commented 7 years ago

I'm sorry to spam you with issues.

I'm trying to get access to the REST api using http://127.0.0.1:8080/api/rest/products/AKNMUG_BP but all I get is a 404 from the web server.

Is there something to add to nginx/apache to get the api working or am I doing something wrong?

damien-carcel commented 7 years ago

No problem, I am happy to see people using those images ^^. REST API works fine for me, but from a script, not from the web browser. From my web browser I have a 401, which is normal. By script, I just followed this documentation: https://docs.akeneo.com/1.6/cookbook/rest_api/get-product.html#how-to-use-rest-api It worked fine.

Erwyn commented 7 years ago

That's strange I only get 404.

I use this:

<?php
$username = "admin";
$apiKey   = "4a051465f12f4831a7d733a39042ba590d1b82bb";
$salt     = "2u4qal71n5kwgg44ss8sk4oogoo0kcw";

$nonce   = uniqid();
$created = date('c');

$digest  = base64_encode(sha1(base64_decode($nonce) . $created . $apiKey.'{'.$salt.'}', true));

$headers = array();
$headers[] = 'CONTENT_TYPE: application/json';
$headers[] = 'Authorization: WSSE profile="UsernameToken"';
$headers[] =
    sprintf(
        'X-WSSE: UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
        $username,
        $digest,
        $nonce,
        $created
    );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:8080/api/rest/products/AKNMUG_BP');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if (false === $result) {
    echo "ERROR:".curl_error($ch)."\n";
} else {
    echo "$result\n";
}

And I get this in return:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>An Error Occurred: Not Found</title>
    </head>
    <body>
        <h1>Oops! An Error Occurred</h1>
        <h2>The server returned a "404 Not Found".</h2>

        <div>
            Something is broken. Please let us know what you were doing when this error occurred.
            We will fix it as soon as possible. Sorry for any inconvenience caused.
        </div>
    </body>
</html>

And even if I go there with the browser I don't get the 401 unauthorized. It looks like the webserver does not know how to serve this.

Please note I am on the nginx/fpm image which is somehow working for now but I'm quite sure I got the same result with the apache one when I tried earlier. I'm gonna try again with the apache one to confirm.

damien-carcel commented 7 years ago

I only tried with the apache image, I will try with nginx too. One more thing, I tried with "localhost" instead of "127.0.0.1". No idea if it can have an effect.

Erwyn commented 7 years ago

Okay, I'm gonna try with the apache image and php5.6. I'll give you the result in a few minutes. I tried with localhost as well to no success.

Erwyn commented 7 years ago

Okay so same result, I get the 404 with the error message.

Erwyn commented 7 years ago

Just to be sure, I'm running this on the pim-community-dev on the master branch

damien-carcel commented 7 years ago

That would explain! Akeneo API is completely reworked on master (future 1.7). The documentation you read is for 1.6.

Erwyn commented 7 years ago

Oh I see. And what is the way to access it now?

damien-carcel commented 7 years ago

There is nothing at the moment but an empty PimApiBundle on master. The old API has been trashed, and the new one is on a separate branch for the moment, until it is finished.

The development is currently done on this branch: https://github.com/akeneo/pim-community-dev/tree/api-web.

Erwyn commented 7 years ago

Okay I see. I have two questions then, because I wanted to add something to the rest api:

Thanks,

damien-carcel commented 7 years ago

Yes, the API will be able to do it. And Akeneo 1.7 is to be released end of February / first week of March (one release every 6 month).

If you want more info about the API, you should ask directly on Akeneo forums or the Akeneo Slack user group (https://akeneopim-ug.slack.com/). That is where you will have most information.

Erwyn commented 7 years ago

Super thank you!

damien-carcel commented 7 years ago

You're welcome :)