1

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': []}
}```
helloyes
  • 13
  • 2

1 Answers1

0

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

Jenny
  • 76
  • 1
  • Hi Jenny, i was trying to pull incremental data using same pattern https://api.europe-west1.gcp.commercetools.com/projectKey/payments?where=lastModifiedAt > 2021-04-16T12:09:38.030Z but its not working. Any idea what am i missing – Anil Sarkar Dec 28 '22 at 06:29
  • As I am not sure where you are doing the queries the query predicate could look something like this: lastModifiedAt>"2021-04-16T12:09:38.030Z" The cURL could look like this: https://api.europe-west1.gcp.commercetools.com/projectKey/payments?where=lastModifiedAt>"2021-04-16T12%3A09%3A38.030Z" To see if your query language is correct, you can also test here: https://impex.europe-west1.gcp.commercetools.com/playground?endpoint=payments&method=read&query-where=lastModifiedAt%3E%222021-04-16T12%3A09%3A38.030Z%22&query-sort-order=asc – Jenny Jan 03 '23 at 16:17