# API Probleme

**URL:** <https://forum.shopware.com/t/api-probleme/57479>\
**Category:** Programmierung\
**Created:** [15. Januar 2019 um 12:58 UTC](https://forum.shopware.com/t/api-probleme/57479 "2019-01-15T12:58:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [15. Januar 2019 um 12:58 UTC](https://forum.shopware.com/t/api-probleme/57479/1 "2019-01-15T12:58:59Z")

</div>

Hallo Zusammen,  
seit Kurzem bekomme ich folgende Fehlermeldung wenn ich die API unserer SW 5.2.9 Shops in PHP ansprechen möchte:

&nbsp;

```
Could not decode json
json_last_error: No error occurred
Raw:
NULL

```

Wenn ich die API im Browser anspreche bekomme ich allerdings eine valide JSON response.  
[https://xxx/api/articles/LV2017?useNumberAsId=true](https://xxx/api/articles/LV2017?useNumberAsId=true)  
&nbsp;

```
require_once('shopware_api.php');

$client = new ApiClient(
    //URL of shopware REST server
    'https://www.xxx.de/',
    //Username
    'xxx',
    //User's API-Key
    'xxx'
);
$article_id = 'LV2017';
$response = $client->get('/api/articles/'.$article_id.'?useNumberAsId=true');

var_dump($response);

```

Wir haben in SW nichts geändert ausser die Installation eines FB Pixel Plugins…

Woran kann das liegen?

&nbsp;

Vielen Dank!

&nbsp;

---

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [15. Januar 2019 um 16:55 UTC](https://forum.shopware.com/t/api-probleme/57479/2 "2019-01-15T16:55:42Z")

</div>

Wenn ich in POSTMAN [https://user:apikey@shop/api/articles/LV2017?useNumberAsId=true](https://user:apikey@shop/api/articles/LV2017?useNumberAsId=true) nutze bekomme ich auch immer 401 - Invalid or missing auth obwohl die Daten stimmen?

---

<div class="post-metadata">

**Author:** ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)\
**Post date:** [15. Januar 2019 um 18:27 UTC](https://forum.shopware.com/t/api-probleme/57479/3 "2019-01-15T18:27:58Z")

</div>

> [@thethe schrieb:](https://forum.shopware.com/profile/20702/thethe "thethe")
> 
> Hallo Zusammen,  
> seit Kurzem bekomme ich folgende Fehlermeldung wenn ich die API unserer SW 5.2.9 Shops in PHP ansprechen möchte:
> 
> &nbsp;
> 
> Could not decode json  
> json\_last\_error: No error occurred  
> Raw:  
> NULL
> 
> Wenn ich die API im Browser anspreche bekomme ich allerdings eine valide JSON response.  
> [https://xxx/api/articles/LV2017?useNumberAsId=true](https://xxx/api/articles/LV2017?useNumberAsId=true)  
> &nbsp;
> 
> require\_once(‚shopware\_api.php‘);
> 
> $client = new ApiClient(  
> //URL of shopware REST server  
> ‚[https://www.xxx.de/](https://www.xxx.de/)‘,  
> //Username  
> ‚xxx‘,  
> //User’s API-Key  
> ‚xxx‘  
> );  
> $article\_id = ‚LV2017‘;  
> $response = $client-\>get(‚/api/articles/‘.$article\_id.‚?useNumberAsId=true‘);
> 
> var\_dump($response);
> 
> Wir haben in SW nichts geändert ausser die Installation eines FB Pixel Plugins…
> 
> Woran kann das liegen?
> 
> &nbsp;
> 
> Vielen Dank!
> 
> &nbsp;

&nbsp;

Ist dein Beispiel vollständig?  
In den DevDocs wird /api an die URL angehängt:&nbsp;[REST API - Basics](https://developers.shopware.com/developers-guide/rest-api/#creating-the-api-client)  
Das fehlt in deinem Beispiel.

Die Postman URL ist für deine Version falsch aufgebaut - da gibt es noch keinen Basic Auth:&nbsp;&nbsp;[REST API - Basics](https://developers.shopware.com/developers-guide/rest-api/#authentication)  
Der ist erst mit 5.3.2 hinzugekommen. In deiner Version musst du den Auth per Header (Digest) senden.&nbsp;

---

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [15. Januar 2019 um 19:58 UTC](https://forum.shopware.com/t/api-probleme/57479/4 "2019-01-15T19:58:04Z")

</div>

Hallo Moritz,

/api habe ich hier doch drin?  
&nbsp;

```
$response = $client->get('/api/articles/'.$article_id.'?useNumberAsId=true');

```

&nbsp;

Danke für den Hinweis bezüglich der Authentifizierung.S  
Mich wundert es halt das die Anfrage erst seit ein paar Tagen nicht mehr läuft - ohne grosse Änderungen auf der SW Seite .  
Wie kann ich denn checken ob es an den Servereinstellungen liegt bzw. was kann ich meinem Hoster fragen?

Vielen Dank!

---

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [16. Januar 2019 um 09:09 UTC](https://forum.shopware.com/t/api-probleme/57479/5 "2019-01-16T09:09:33Z")

</div>

Über Postman bekomme ich jetzt alles korrekt zurück.  
Warum in aller Welt funktioinert dann der Aufruf nicht mehr?

&nbsp;

```
echo 'API TEST!';
require_once('shopware_api.php');

$client = new ApiClient(
    //URL of shopware REST server
    'https://shop.xxx.de/api',
    //Username
    'xxx',
    //User's API-Key
    'xxx'
);

$response = $client->get('/articles/LV2017?useNumberAsId=true');

print_r($response);

```

iimmer noch  
&nbsp;

```
Could not decode json
json_last_error: No error occurred
Raw:

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)\
**Post date:** [16. Januar 2019 um 09:24 UTC](https://forum.shopware.com/t/api-probleme/57479/6 "2019-01-16T09:24:18Z")

</div>

Artikel vielleicht defekt?  
Mal einen anderen probiert?  
Was ist bei einem direktaufruf der ID?

---

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [16. Januar 2019 um 09:33 UTC](https://forum.shopware.com/t/api-probleme/57479/7 "2019-01-16T09:33:52Z")

</div>

Artikel ist in Ordung. JSON in Postman ist valide. Mit mehreren Artikeln getestet…Direktaufruf ID gleiches ergebnis ☹

---

<div class="post-metadata">

**Author:** ![shopyphus](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shopyphus](https://forum.shopware.com/u/shopyphus)\
**Post date:** [16. Januar 2019 um 09:46 UTC](https://forum.shopware.com/t/api-probleme/57479/8 "2019-01-16T09:46:38Z")

</div>

Ist vielleicht der führende “/” beim Aufruf zuviel? Probier mal

```
$client->get('articles/LV2017?useNumberAsId=true');

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![thethe](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@thethe](https://forum.shopware.com/u/thethe)\
**Post date:** [17. Januar 2019 um 12:07 UTC](https://forum.shopware.com/t/api-probleme/57479/9 "2019-01-17T12:07:00Z")

</div>

Hallo,

&nbsp;

vielen Dank für Euere Hilfe.  
Der Fehler ist behoben - es war ein falsch implementiertes SSL Zwischenzertifikat in Plesk.

&nbsp;

Viele Gruesse & Danke
