Wenn ich ich die api per browser plugin anspreche zB. https://127.0.0.1/shopware/api/orders
bekomme ich auch eine response mit allen orders und http status 200.
also simmt i.was mit dem php nicht. hier das ganze skript
apiUrl = rtrim($apiUrl, '/') . '/';
//Initializes the cURL instance
$this->cURL = curl_init();
curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->cURL, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($this->cURL, CURLOPT_USERAGENT, 'Shopware ApiClient');
curl_setopt($this->cURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($this->cURL, CURLOPT_USERPWD, $username . ':' . $apiKey);
curl_setopt(
$this->cURL,
CURLOPT_HTTPHEADER,
['Content-Type: application/json; charset=utf-8']
);
}
public function call($url, $method = self::METHOD_GET, $data = [], $params = [])
{
if (!in_array($method, $this->validMethods)) {
throw new Exception('Invalid HTTP-Methode: ' . $method);
}
$queryString = '';
if (!empty($params)) {
$queryString = http_build_query($params);
}
$url = rtrim($url, '?') . '?';
$url = $this->apiUrl . $url . $queryString;
$dataString = json_encode($data);
curl_setopt($this->cURL, CURLOPT_URL, $url);
curl_setopt($this->cURL, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $dataString);
$result = curl_exec($this->cURL);
$httpCode = curl_getinfo($this->cURL, CURLINFO_HTTP_CODE);
return $this->prepareResponse($result, $httpCode);
}
public function get($url, $params = [])
{
return $this->call($url, self::METHOD_GET, [], $params);
}
public function post($url, $data = [], $params = [])
{
return $this->call($url, self::METHOD_POST, $data, $params);
}
public function put($url, $data = [], $params = [])
{
return $this->call($url, self::METHOD_PUT, $data, $params);
}
public function delete($url, $params = [])
{
return $this->call($url, self::METHOD_DELETE, [], $params);
}
protected function prepareResponse($result, $httpCode)
{
echo "HTTP: $httpCode";
if (null === $decodedResult = json_decode($result, true)) {
$jsonErrors = [
JSON_ERROR_NONE => 'No error occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been reached',
JSON_ERROR_CTRL_CHAR => 'Control character issue, maybe wrong encoded',
JSON_ERROR_SYNTAX => 'Syntaxerror',
];
echo 'Could not decode json';
echo 'json_last_error: ' . $jsonErrors[json_last_error()];
echo 'Raw:';
echo '' . print_r($result, true) . '';
return;
}
if (!isset($decodedResult['success'])) {
echo 'Invalid Response';
return;
}
if (!$decodedResult['success']) {
echo 'No Success';
echo '' . $decodedResult['message'] . '';
if (array_key_exists('errors', $decodedResult) && is_array($decodedResult['errors'])) {
echo '' . join('', $decodedResult['errors']) . '';
}
return;
}
echo 'Success';
if (isset($decodedResult['data'])) {
echo '' . print_r($decodedResult['data'], true) . '';
}
return $decodedResult;
}
}
$client = new ApiClient(
//URL of shopware REST server
'https://127.0.0.1/shopware/api',
//Username
'user',
//User's API-Key
'xxx'
);
$client->get('orders');
?>
@R4M die URL sollte ja dann stimmen