Search code examples
jsonpython-requestsgetbulkcommercetools

How to filter by date when accessing the commercetools platform with cURL


I need to filter a request by date to pull some data from Commercetools. I have the below currently but it is not filtering response = requests.get('https://api.<addresshere>?limit=500&filter=results.createdAt=2021-10-10T21:31:31.231Z', headers={'Authorization': 'Bearer <token>'}, stream=True)

The json structure is :

 'offset': 0,
 'count': 0,
 'total': 0,
 'results': [{'id': 'test',
   'version': 1,
   'lastMessageSequenceNumber': 1,
   'createdAt': '2021-10-04T22:37:38.238Z',
   'lastModifiedAt': '2021-10-04T22:37:38.238Z',
   'lastModifiedBy': {'clientId': 'test',
    'isPlatformClient': test},
   'createdBy': {'clientId': 'test',
    'isPlatformClient': test},
   'key': 'test',
   'amountPlanned': {'type': 'test',
    'currencyCode': 'GBP',
    'centAmount': 0,
    'fractionDigits': 2},
   'paymentMethodInfo': {'paymentInterface': 'test', 'method': 'test'},
   'paymentStatus': {'interfaceCode': 'test',
    'interfaceText': 'test',
    'state': {'typeId': 'test',
     'id': 'test'}},
   'transactions': [{'id': 'test',
     'timestamp': '2021-10-04T22:37:38.199Z',
     'type': 'test',
     'amount': {'type': 'test',
      'currencyCode': 'NZD',
      'centAmount': 0,
      'fractionDigits': 2},
     'interactionId': '1',
     'state': 'test'}],
   'interfaceInteractions': []}
}```

Solution

  • It looks like you are trying to query on the payments endpoint. The payments API does not have a search but a query capability and hence you may want to look into query predicates rather than filters which are currently only used on product projections search.

    The predicate could look something like this: createdAt="2021-04-16T12:09:38.030Z"

    The curl then would look something like this: GET 'https://api.europe-west1.gcp.commercetools.com/projectKey/payments?where=createdAt%3D%222021-04-16T12%3A09%3A38.030Z%22'

    For more information about the predicate language you can also take a look at our documentation: https://docs.commercetools.com/api/predicates/query#top