affilinet / productdata-php-sdk

Documentation and Code Package of PHP SDK for affilinet Product Data Webservices

Home Page:http://developer.affili.net/productdata-php-sdk/documentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

403 Status on Live server

benjaminfunk opened this issue · comments

`$objGuzzleClient = new \GuzzleHttp\Client(
[
'verify' => isEnvironment('development') ? false : true
]);

$objHttpClient = new \Affilinet\ProductData\HttpClient\GuzzleClient($objGuzzleClient);

$arrConfig =
[
	'publisher_id' => xxxxx,
	'product_webservice_password' => 'xxxxx',
	'http_client' => $objHttpClient
];

$objClient = new \Affilinet\ProductData\AffilinetClient($arrConfig);

$objProductSearch = (new \Affilinet\ProductData\Requests\ProductsRequest($objClient));

$objProductSearch->pageSize(500);
$objProductSearch->addFilterQuery('EAN', '04260415994004');

$objProductsResponse = $objProductSearch->send();`

This code works well on my local environment. But if i use it on my live server i always get a 403.

{"ErrorMessages":[{"Key":"20300007","Value":"PublisherId is not valid. The PublisherId has to be greater than 0."}]}

cURL - installed 7.38.0
openSSL - installed OpenSSL/1.0.1t
zlib - installed

Any ideas why it isnt working and how i can debug this?

Hey,

for my tests its hard-coded. But a string will not solve the problem.

I cant comment. WTF!?

Hi Benjamin,
Is the publisher ID hard-coded? Could you please try if it works if you add it as a string?

Hey,

for my tests its hard-coded. But a string will not solve the problem.

I tried a simple Guzzle Request

`$client = new \GuzzleHttp\Client(
[
'verify' => isEnvironment('development') ? false : true
]);

$res = $client->request('GET', 'https://product-api.affili.net/V3/productservice.svc/JSON/SearchProducts?PublisherId=xxx&Password=xxxx&Query=ipod');

echo $res->getStatusCode();
echo $res->getHeaderLine('content-type');
echo $res->getBody();`

This will work! But its nearly the same, except the Affilinet Lib.

Did you maybe set an Environment Variable named 'AFFILINET_PUBLISHER_ID'

This could overwrite your config, see code here: https://github.com/affilinet/productdata-php-sdk/blob/master/src/Affilinet/ProductData/AffilinetClient.php#L65

In my real application i have set this environment var. But with the right value.

In my current sandbox the var is not set. So this cant be the problem

Ok i just did a re-check: The environment var gets overwritten by the hardcoded publisher id. The same applies to you publisher password. So on your live-server the env var will not be used.

Are you german? Will be a bit easier for me ;)

yes :)

Bin um einiges weiter gekommen. Folgendes ist mir aufgefallen. In meinem simple Guzzle Request nutze ich die Methode request

$client->request();

Der GuzzleClient nutzt allerdings eine send Methode (https://github.com/affilinet/productdata-php-sdk/blob/master/src/Affilinet/ProductData/HttpClient/GuzzleClient.php#L49)

Wenn ich die Zeile 49 nun durch folgendes ersetze

$psr7Response = $this->guzzle->request('GET', $request->getUri()->__toString());

funktioniert es! :)

Ist meiner Meinung nach noch nicht die sauberste Lösung, aber du solltest damit denke ich schnell zu einer Lösung kommen.

Interessant, dass es hier zu unterschiedlichem Verhalten kommt. Muss mal recherchieren ob es hier irgendwelche Änderungen in Guzzle gab. Bzw. von welchen PHP Extensions das abhängt.

Gibt es schon irgendwelche Neuigkeiten/Lösungen oder muss ich vorerst auf ein Workaround zurückgreifen?

Hallo Benjamin,
ich habe versucht den Fall nachzustellen, mir ist es allerdings nicht gelungen.
Die Ursache liegt also nicht im Code sondern in der Umgebung.

Wir hatten ja im Juni telefoniert, und ich bin mir sicher, dass es die genannte PHP-Sicherheitserweiterung ist die hier die Probleme macht.
Diese würde ich deaktivieren, sofern sie nicht unbedingt benötigt wird.

Sorry, dass ich hier nicht weiter helfen kann.

Hey,

kein Problem. Ich hab mich nochmal ran gesetzt und habe den Fehler gefunden :)

https://github.com/affilinet/productdata-php-sdk/blob/master/src/Affilinet/ProductData/Requests/AbstractRequest.php#L56

Das Problem ist das http_build_query auf manchen Servern automatisch ein "&" nach "& amp;" ersetzt. Wenn man es in HTML verwendet ist das kein Problem. Als Request URI macht es allerdings Probleme.

Dieses Verhalten ist bekannt: http://php.net/manual/de/function.http-build-query.php#102324

Am einfachten wäre vermutlich die Verwendung von "http_build_query($query, '', '&');". Könntest du das mal durch deine Tests überprüfen lassen? Man könnte diese Option ja auch optional per Variable umstellen.

PS: Quick Fix -> http://php.net/manual/de/ini.core.php#ini.arg-separator.output

Ja großartig, man lernt aber auch nie aus! Habe eben die Version 1.0.1 veröffentlicht. Darin ist es behoben.