DankeDanke MemberComments: 69 Received thanks: 7 Member since: November 2016

Den Code den ich habe gibt nur alle Produkte aus, jedoch bekomme ich es nicht hin die Filter anzuweden: 

In dem Postman kann ich filter anweden, aber Postman hat keinen guzzle integriert wie shopware. 

Gerne würde ich 1,2 beispiele für funktierende GET und POST operationen hinbekommen. 

Danke im Voraus.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once '../vendor/autoload.php';
use GuzzleHttp\Client;

$client = new GuzzleHttp\Client([
          'base_uri' => 'https://www.plintenburg.com',
          'timeout' => 2.0,
          'headers' => ['Content-Type' => 'application/json'],'verify' => false,]);

 $clientId = "SWIAEHBRZWRUBTDBCNJ2SVLNTW";
 $clientSecret = "dzFNMEZXWUxpZFBucnRaS0g5cHJRSVFvNVUxNkZzc2YzR0pPNHM";

$body1 = json_encode([
            'client_id' => $clientId,
            'client_secret' => $clientSecret,
	    'grant_type' => 'client_credentials',
	    'scopes' => 'write',
    ]);

$response = $client->post(
	    '/api/oauth/token',
	    [
		'Content-Type' => 'application/json',
		'body' => $body1
	    ]
	);
$token = json_decode($response->getBody()->getContents(), true);
//Das ist die TokenAcces ausgebe!!
//print_r($token);



//my first attempt at using the body variable. Without success
$inhlattest ='{
    "ids": [
        "11dc680240b04f469ccba354cbf0b967", 
        "1901dc5e888f4b1ea4168c2c5f005540",
        "1f54875c658f464f95c198b9137391c4"
    ],
    "includes": {
        "product": ["id", "name"]
    }
}';

//my second attempt at using the body variable. Without success 
$inhalt ='{
    "filter": [
        { "type": "equals", "field": "productNumber", "value": "SWDEMO10002" }
    ],
    "includes": {
        "product": ["id", "name", "productNumber"]
    }
}';


echo $inhalt;


$token = json_decode((string) $response->getBody(), true)['access_token'];
    // mit access_token endpunkt auslesen
    if (isset($token)) {
	    $response = $client->request('POST','/api/v3/search/product', 
	[
	    	'headers' => [
			'User-agent'=> 'Mozilla/5.0',
			'Authorization' => 'Bearer ' . $token,
			'Content-Type' => 'application/json',
			'Content-Length' => '0',
			'Accept'=> '*/*',
		 	'Accept-Encoding'=> 'gzip',
			],
	],
	['body' => $inhalt]
);
//echo $response->getBody();
        // Ausgabe
        //return $response;
$body = $response->getBody();
$json_string = json_decode($body, JSON_PRETTY_PRINT);
header('Content-Type: application/json');
print_r($json_string);

    } else {
        return response()->json(['error' => request('error')]);
    }

?>

 

Sign In or Register to comment.