Browse code

Optimize queryAPI method

Benjamin Roth authored on18/03/2025 11:29:43
Showing1 changed files
... ...
@@ -303,7 +303,7 @@ class Shopware
303 303
         return $this->sendRequest('search/order-line-item',$options,'POST');
304 304
     }
305 305
 
306
-    public function queryAPI(string $strUrlFragment, ?string $strBody, string $strMethod = 'GET', bool $blnAuthenticate=true): ResponseInterface
306
+    public function queryAPI(string $strUrlFragment, null|string|array $body, string $strMethod = 'GET', bool $blnAuthenticate=true): ResponseInterface
307 307
     {
308 308
         $options = [
309 309
             'headers' => [
... ...
@@ -317,9 +317,14 @@ class Shopware
317 317
             $options['headers'][] = $this->getAuthentication();
318 318
         }
319 319
 
320
-        if ($strBody !== null)
320
+        if ($body !== null)
321 321
         {
322
-            $options['body'] = $strBody;
322
+            if (is_array($body))
323
+            {
324
+                $options['body'] = json_encode($body);
325
+            } else {
326
+                $options['body'] = $body;
327
+            }
323 328
         }
324 329
 
325 330
         return $this->sendRequest($strUrlFragment,$options,$strMethod);