LurgenB
LurgenB

Reputation: 13

Object Filter for Invoice Date not working

Trying to use the following REST call in Javascript to retrieve invoices for a specific date:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"isDate","options":[{"name":"date","value":["05/01/2018"]}]}}}&objectMask=mask[createDate]

however it always fails with error invalid argument. I have even tried using the between dates answer from this previous question:

Object Filter for Inovice create date

But I still get invalid argument error.

Upvotes: 0

Views: 95

Answers (2)

LurgenB
LurgenB

Reputation: 13

Thanks Fernando. Turns out I was not formatting my URL correctly in Javascript. In case anyone else has the same issue, I needed to define the filter as follows:

var filter = JSON.stringify({"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["05/01/2018 00:00:00"]},{"name":"endDate","value":["05/01/2018 23:59:59"]}]}}});

Then my API call is this:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getInvoices?objectFilter=' + encodeURIComponent(filter) + '&objectMask=mask[invoiceTopLevelItems[totalRecurringAmount]]

Upvotes: 0

Fernando Iquiza
Fernando Iquiza

Reputation: 531

The error "invalid argument" you got is more related to the Javascript call itself.

Currently the api call you are sending and its structure is correct, although there´s an issue with the specific "isDate" operation returning empty api response, but this was reported and other operations are working properly using filters.

Meanwhile I found a workaround, you can make use of the "betweenDate" and specify the same day, for example please see below:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["05/01/2018 00:00:00"]},{"name":"endDate","value":["05/01/2018 23:59:59"]}]}}}&objectMask=mask[createDate]

In my case I got the following response for the exact date (just as 'isDate' would work):

[
    {
        "createDate": "2018-05-01T02:23:56-04:00"
    },
    {
        "createDate": "2018-05-01T08:34:17-04:00"
    }
]

Upvotes: 0

Related Questions