CyberSource/cybersource-rest-samples-csharp

How to specify query parameters for CreateSearchRequest.cs?

Closed this issue · 6 comments

On the page,
https://github.com/CyberSource/cybersource-rest-samples-csharp/blob/master/src/Samples/TransactionSearch/CoreServices/CreateSearchRequest.cs
the Query parameter is set like this:
Query = "clientReferenceInformation.code:TC50171_3 AND submitTimeUtc:[NOW/DAY-7DAYS TO NOW/DAY+1DAY}",

Is this the correct syntax?
there is a left bracket, and a right brace.
just doesn't look right to me.

And the documentation is not any clearer,
https://developer.cybersource.com/api/developer-guides/dita-txn-search-details-rest-api-dev-guide-102718/txn_search_api/creating_txn_search_request.html

says "String that contains the filters and variables for which you want to search. Currently, only clientReferenceInformation.code is available. More filters will be added in the future."

I am trying to write some C# code to download transaction details, without knowing the transaction ids, for a particular date range.

Thanks!

Hi, Thanks for writing to us. The syntax is in alignment with the Apache Solr Date query. You can read about it here. Please feel free to reach out to us in case of any other query.

Hi snavinch,
Thanks for that link.
I modified my c# code so that the CreateSearchRequest looks like this:
{class CreateSearchRequest { Save: True Name: TSS search Timezone: America/Los_Angeles Query: submitTimeUtc:[2020-02-07 TO 2020-02-08] Offset: 0 Limit: 1000 Sort: id:asc, submitTimeUtc:asc } }

I'm not using the query:
[NOW/DAY-2DAYS TO NOW/DAY-1DAY} because this actually uses the time component of NOW.
And I can not guarantee that my job runs at exactly the same time everyday.

I'm supplying the query as specified here, https://lucene.apache.org/solr/guide/6_6/working-with-dates.html#WorkingwithDates-DateRangeFormatting

But this errors out:
{"_links":{"self":{"href":"https://api.cybersource.com/tss/v2/searches"}},"invalidFields":{"name":"query","reasonMessage":"Date parsing failed for input: 2020-02-07","reasonMessageKey":null},"message":"Incorrectly formatted query string","messageKey":"INCORRECT_QUERY_STRING","missingFields":null}

thanks again, Alan

May I please get an update on this issue?
Thanks

May I please get an update on this issue?
I would really, really like to be able to query
using submitTimeUtc:[2020-02-07 TO 2020-02-08]

Thanks

Hi, Apologies for the delayed response.

The date format used isn’t correct. We have a standard way to include custom date range in epoch format,
For eg. submitTimeUtc:[1556712000000 TO 1556757600000]

Here is an explanation of how to use submitTimeUtc field -

submitTimeUtc support range queries and the format for that is as below,

submitTimeUtc:[startDate TO endDate}

where startDate and endDate is a valid Date math expression as described below -

• SubmitTimeUtc supports date math expressions, which makes it easy to create times relative to fixed moments in time, include the current time which can be represented using the special value of “NOW”.

• "NOW" is used to represent current moment in time.

Date Math Syntax:

• Date math expressions consist either adding some quantity of time in a specified unit, or rounding the current time by a specified unit. expressions can be chained and are evaluated left to right.
• For example: this represents a point in time two months from now: NOW+2MONTHS
• A slash is used to indicate rounding. This represents the beginning of the current hour: NOW/HOUR so e.g if lets say right now its 4.12 pm (which is represented by NOW). Then NOW/HOUR would mean beginning of that hour. i.e 4.00 pm. Similarly NOW/MONTH will round up to the beginning of the month. e.g lets say currently NOW is 4th May, 2019, 4.23 pm. Then doing NOW/MONTH will result to 1st May,2019,12.00 am. (So it round up to the beginning of the day of the month.)
• The following example computes (with millisecond precision) the point in time six months and three days into the future and then rounds that time to the beginning of that day: NOW+6MONTHS+3DAYS/DAY.

The valid values in the date Math Syntax:
• DAY or DAYS
• MONTH or MONTHS
• MINUTE or MINUTES
• HOUR or HOURS

Note about the parenthesis:
There are two kinds of parenthesis we can use in the syntax,
• '[' or ']' -> this means the date is included.
• '{' or '}' -> this means the date is excluded.

For e.g, lets say the query is submitTimeUtc:[NOW/DAY-1DAY TO NOW/DAY}
and lets say 'NOW' at this point represents May 2nd,2019,4.12 pm.
Then, the above will have -
start date - May 1st,2019, 12.00 am.
endDate - May 2nd, 12.00 am.

So, our syntax will reduce to submitTimeUtc:[May 1st,2019, 12.00 am TO May 2nd,2019, 12.00 am}
Since we are using '[' this in the start date it is included
However since for endDate we have '}', its excluded meaning that this will only have transactions until May 1st,2019,11.59.9999 pm. Essentially the transaction which has date as May 2nd ,2019,12.00 am will not be included in this.

Some other examples:
'All transactions for Last hour' - 'transactionDate:[NOW/HOUR-1HOUR TO NOW/HOUR}',
'All transactions for today untill'- 'transactionDate:[NOW/DAY TO NOW/DAY+1DAY}',
'yesterday'- 'transactionDate:[NOW/DAY-1DAY TO NOW/DAY}',
'last7Days'- 'transactionDate:[NOW/DAY-7DAYS TO NOW/DAY+1DAY}',
'monthToDate'- 'transactionDate:[NOW/MONTH TO NOW/DAY+1DAY}',
'lastMonth'- 'transactionDate:[NOW/MONTH-1MONTH TO NOW/MONTH}',
'lastSixMonths'- 'transactionDate:[NOW/DAY-6MONTHS TO NOW/DAY+1DAY}'

Thanks snavinch, that info is very helpful.