api-php-client icon indicating copy to clipboard operation
api-php-client copied to clipboard

auto switch to http from https with error

Open dankoz51 opened this issue 3 years ago • 4 comments

For some reason this switches to http from https.

  1. Configure client to use https url
  2. use a cursor paging, after the second page you get a http redirect error (as there is not http it redirects to https) 3 the fist page worked find, its the second page that seems to want to go to http over https

Sample client call `<?php ini_set('display_errors', 1); require_once 'vendor/autoload.php'; require_once('./env.php');

$clientBuilder = new \Akeneo\Pim\ApiClient\AkeneoPimClientBuilder($_ENV["AKENEO_SERVER"]); $client = $clientBuilder->buildAuthenticatedByPassword($_ENV["AKENEO_API_CLIENT_ID"], $_ENV["AKENEO_API_SECRET"], $_ENV["AKENEO_API_USER"] , $_ENV["AKENEO_API_PASSWORD"]);

$searchBuilder = new \Akeneo\Pim\ApiClient\Search\SearchBuilder();

$searchBuilder ->addFilter('enabled', '=', true);

$searchFilters = $searchBuilder->getFilters(); $products = $client->getProductApi()->all(50,['search' => $searchFilters, 'scope' => 'Ecommerce']);

echo "starting:".PHP_EOL; foreach ($products as $product) { echo print_r($product).PHP_EOL; } `

Error message PHP Fatal error: Uncaught Akeneo\Pim\ApiClient\Exception\RedirectionHttpException: Moved Permanently (see https://api.akeneo.com/php-client/exception.html#client-exception) in /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Client/HttpExceptionHandler.php:49 Stack trace: #0 /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Client/HttpClient.php(77): Akeneo\Pim\ApiClient\Client\HttpExceptionHandler->transformResponseToException(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Client/AuthenticatedHttpClient.php(64): Akeneo\Pim\ApiClient\Client\HttpClient->sendRequest('GET', 'http://pim.x...', Array, NULL) #2 /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Pagination/Page.php(132): Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient->sendRequest('GET', 'http://pim.x...', Array) #3 /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Pagination/Page.php(76): Akeneo\Pim\ApiClient\Pagination\Page in /Users/dankoz/cws-automation/vendor/akeneo/api-php-client/src/Client/HttpExceptionHandler.php on line 49

dankoz51 avatar Sep 06 '22 18:09 dankoz51

Hi @dankoz51 Can you check the raw JSON output from the first call? It looks like pagination links sent by the API are http. It would be something to fix on the PIM side

LevFlavien avatar Sep 13 '22 12:09 LevFlavien

Yes they are http in the output but dont know where to fix that on the pim side, going to dig around

starting: Array ( [_links] => Array ( [self] => Array ( [href] => http:/.....

dankoz51 avatar Sep 13 '22 13:09 dankoz51

The answer is set HTTPS=On to the .env file

dankoz51 avatar Oct 04 '22 19:10 dankoz51

The PIM .env file?

LevFlavien avatar Oct 07 '22 08:10 LevFlavien