softlayer-java icon indicating copy to clipboard operation
softlayer-java copied to clipboard

Can't access invoice details

Open aguse1 opened this issue 7 years ago • 6 comments

Hi.

We are trying to retrieve an invoice's details but are having troubles getting to the items on an invoice. We've set the mask using the following: as.setMask("mask[invoiceTopLevelItemCount,invoiceTotalAmount,amount]");

It returns the count and amount as expected. When we change the mask to retrieve the returned invoices object is null. We tried using the following masks:

as.setMask("mask[invoiceTopLevelItems]"); or as.setMask("mask[items]");

Here is an example of the code:

	ApiClient c = new RestApiClient().withCredentials("xxxx", "xxxx");
	Account.Service as = Account.service(c);
	as.setMask("mask[items]");

	try {

		List<com.softlayer.api.service.billing.Invoice> invoices = as.getInvoices();

Unfortunately the invoices List object (in the last line) is null with either mask set. Is there something we should be doing differently? This was also part of the SL support case CS1011381.

Thanks!

aguse1 avatar Oct 11 '19 00:10 aguse1

@FernandoOjeda take a look at this when you can, thanks.

allmightyspiff avatar Oct 11 '19 01:10 allmightyspiff

Sure, I will check it.

FernandoOjeda avatar Oct 11 '19 14:10 FernandoOjeda

@aguse1 Hi, the null result that you got may be because the request is trying to get a lot of information.

Try using resultLimit, see the following example:

ApiClient c = new RestApiClient().withCredentials("xxxx", "xxxx"); Account.Service as = Account.service(c); as.setMask("mask[items]"); as.setResultLimit(new ResultLimit(10));

try {

	List<com.softlayer.api.service.billing.Invoice> invoices = as.getInvoices();

FernandoOjeda avatar Oct 11 '19 14:10 FernandoOjeda

Hi @FernandoOjeda .

Thanks for the reply. Your suggestion seems to work for most invoices but the one invoice I want to access is throwing an error. Here is the sample code:

as.setMask("mask[items]");
    as.setResultLimit(new ResultLimit(6219,2));
	try {

		List<com.softlayer.api.service.billing.Invoice> invoices = as.getInvoices();

The last line throws the following exception:

java.lang.RuntimeException: Expected 'complexType' as first property at com.softlayer.api.json.GsonJsonMarshallerFactory$EntityTypeAdapter.read(GsonJsonMarshallerFactory.java:187) at com.softlayer.api.json.GsonJsonMarshallerFactory$EntityTypeAdapter.read(GsonJsonMarshallerFactory.java:140) at com.softlayer.api.json.GsonJsonMarshallerFactory$ListOrSingleObjectTypeAdapter.read(GsonJsonMarshallerFactory.java:405) at com.softlayer.api.json.GsonJsonMarshallerFactory$ListOrSingleObjectTypeAdapter.read(GsonJsonMarshallerFactory.java:383) at com.google.gson.Gson.fromJson(Gson.java:927) at com.google.gson.Gson.fromJson(Gson.java:892) at com.softlayer.api.json.GsonJsonMarshallerFactory.fromJson(GsonJsonMarshallerFactory.java:84) at com.softlayer.api.RestApiClient$ServiceProxy.logAndHandleResponse(RestApiClient.java:298) at com.softlayer.api.RestApiClient$ServiceProxy.invokeService(RestApiClient.java:325) at com.softlayer.api.RestApiClient$ServiceProxy.invoke(RestApiClient.java:489) at com.sun.proxy.$Proxy0.getInvoices(Unknown Source) at com.ibm.slapi.SLAPITest.test(SLAPITest.java:1388) at com.ibm.slapi.SLAPITest.main(SLAPITest.java:1439)

Could it be the one invoice is too large?

Thanks for your help!

aguse1 avatar Oct 11 '19 16:10 aguse1

The items property can certainly get quite large for certain invoices, so it is possible that invoice has too many properties to return at once.

My suggestion would be to use as.getInvoices(); to just get the basic info about each invoice. And to then use https://sldn.softlayer.com/reference/services/SoftLayer_Billing_Invoice/getItems/ (with a result Limit) to get every item on each invoice.

allmightyspiff avatar Oct 11 '19 18:10 allmightyspiff

@FernandoOjeda - Thank you for the help! This helped us get exactly what we needed!

aguse1 avatar Oct 12 '19 02:10 aguse1