SW6 API search mit includes und/oder filter

Hallo,

ich rufe die Bestellungen des Shops über folgende Route ab: /api/search/order

Das funktioniert soweit. Ich möchte die Ergebnisse aber filtern bzw. auf bestimmte Felder begrenzen oder nur offenen Bestellungen abrufen.

Ich habe folgendes probiert, allerdings werden weder die Filter noch die includes angewendet. Es wird immer alles ausgegeben bzw. abgerufen:

function get_orders() {

    $curl = curl_init();

    curl_setopt_array($curl, [
      CURLOPT_URL => $this->shopurl."/api/search/order",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => json_encode([

        'filter' => [
            [
                    'type' => 'range',
                    'field' => 'createdAt',
                    'parameters' => [
                                    'gte' => '2023-09-22T12:00:00.333+00:00'
                    ]
            ]
        ]
        
      ]),          
      CURLOPT_HTTPHEADER => [
        "Accept: application/json",
        "Authorization: Bearer ".$this->token
      ],
    ]);
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);

    return $response;
}

ODER:

function get_orders() {

    $curl = curl_init();

    curl_setopt_array($curl, [
      CURLOPT_URL => $this->shopurl."/api/search/order",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => json_encode([

        'includes' => [
            'order' => [
                    'id',
                    'createdAt',
                    'orderNumber'                        
            ]
        ]
                    
      ]),          
      CURLOPT_HTTPHEADER => [
        "Accept: application/json",
        "Authorization: Bearer ".$this->token
      ],
    ]);
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);

    return $response;
}

Also das hier geht auf jeden Fall:

{
	'limit': 1000,
	'sort': [{
		'field': 'createdAt',
		'order': 'ASC'
	}],
	'includes': {
		'order': ['id', 'orderNumber', 'orderDateTime', 'orderCustomer', 'lineItems', 'transactions', 'billingAddress', 'deliveries', 'shippingCosts'],
		'country': ['id', 'iso', 'iso3'],
		'order_address': ['id', 'firstName', 'lastName', 'additionalAddressLine1', 'additionalAddressLine2', 'company', 'street', 'zipcode', 'city', 'country'],
		'order_line_item': ['id', 'label', 'position', 'quantity', 'unitPrice', 'product', 'payload'],
		'order_transaction': ['id', 'paymentMethod', 'extensions'],
		'payment_method': ['id', 'distinguishableName'],
		'order_customer': ['id', 'email'],
		'order_delivery': ['id', 'shippingOrderAddress'],
		'calculated_price': ['totalPrice']
	},
	'filter': [{
		'type': 'not',
		'operator': 'or',
		'queries': [{
			'type': 'equals',
			'field': 'order.stateMachineState.technicalName',
			'value': 'completed'
		}, {
			'type': 'equals',
			'field': 'order.stateMachineState.technicalName',
			'value': 'cancelled'
		}]
	}, {
		'type': 'equals',
		'field': 'transactions.stateMachineState.technicalName',
		'value': 'paid'
	}],
	'associations': {
		'lineItems': {
			'associations': {
				'product': {}
			}
		},
		'transactions': {
			'associations': {
				'payonePaymentOrderTransactionData': {},
				'paymentMethod': {}
			}
		},
		'billingAddress': {
			'associations': {
				'country': {}
			}
		},
		'deliveries': {
			'associations': {
				'shippingOrderAddress': {
					'associations': {
						'country': {}
					}
				}
			}
		}
	}
}

Wie du das in PHP baust musst halt mal zusammensuchen…

Ich habe deinen Code in die CURLOPT_POSTFIELDS eingefügt s.u.

Es werden immer noch alle Bestellungen abgerufen…?
Jemand eine Idee was bei den CURLOPT_POSTFIELDS nicht finktioniert?

function get_orders() {

    $curl = curl_init();

    curl_setopt_array($curl, [
      CURLOPT_URL => $this->shopurl."/api/search/order",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "{
        'limit': 1000,
        'sort': [{
          'field': 'createdAt',
          'order': 'ASC'
        }],
        'includes': {
          'order': ['id', 'orderNumber', 'orderDateTime', 'orderCustomer', 'lineItems', 'transactions', 'billingAddress', 'deliveries', 'shippingCosts'],
          'country': ['id', 'iso', 'iso3'],
          'order_address': ['id', 'firstName', 'lastName', 'additionalAddressLine1', 'additionalAddressLine2', 'company', 'street', 'zipcode', 'city', 'country'],
          'order_line_item': ['id', 'label', 'position', 'quantity', 'unitPrice', 'product', 'payload'],
          'order_transaction': ['id', 'paymentMethod', 'extensions'],
          'payment_method': ['id', 'distinguishableName'],
          'order_customer': ['id', 'email'],
          'order_delivery': ['id', 'shippingOrderAddress'],
          'calculated_price': ['totalPrice']
        },
        'filter': [{
          'type': 'not',
          'operator': 'or',
          'queries': [{
            'type': 'equals',
            'field': 'order.stateMachineState.technicalName',
            'value': 'completed'
          }, {
            'type': 'equals',
            'field': 'order.stateMachineState.technicalName',
            'value': 'cancelled'
          }]
        }, {
          'type': 'equals',
          'field': 'transactions.stateMachineState.technicalName',
          'value': 'paid'
        }],
        'associations': {
          'lineItems': {
            'associations': {
              'product': {}
            }
          },
          'transactions': {
            'associations': {
              'payonePaymentOrderTransactionData': {},
              'paymentMethod': {}
            }
          },
          'billingAddress': {
            'associations': {
              'country': {}
            }
          },
          'deliveries': {
            'associations': {
              'shippingOrderAddress': {
                'associations': {
                  'country': {}
                }
              }
            }
          }
        }
      }",          
      CURLOPT_HTTPHEADER => [
        "Accept: application/json",
        "Authorization: Bearer ".$this->token
      ],
    ]);
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);

    return $response;
}