Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

ibm cloud infrastructure - Getting "error": "Internal Error" on Postman and getting error Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

While hitting below Softlayer rest url from Postman getting error:

"Internal Error"

And when hitting the same rest url from java code using spring restTemplate getting error as

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token.

https://api.softlayer.com/rest/v3/SoftLayer_Account/<Account-ID>/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["03/25/2017 00:00:00"]},{"name":"endDate","value": ["04/24/2017 23:59:59"]}]},"typeCode":{"operation":"RECURRING"}}}&objectMask=mask[id,items[id,recurringFee,recurringTaxAmount,oneTimeFee,oneTimeTaxAmount,description,hostName,domainName,hourlyRecurringFee,laborFee,laborTaxAmount,setupFee,setupTaxAmount,category[name],location[longName],billingItem[id,activeFlag,hourlyFlag,allowCancellationFlag,cancellationDate,orderItem[id,order[id,userRecord[username]]]]]]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The REST URL you posted is working when the invoices don't have a lot of items. You are getting "Internal Error" because internally some invoices are returning the error "Allowed memory size of 402653184 bytes exhausted (tried to allocate 131072 bytes)", this when is added

orderItem[id,order[id,userRecord[username]]]

I got the same error with just one invoice, on my case the invoice have more than 1500 items, this is a lot of items.

Your mask is very big in depth and there are a lot of data to retrieve, for that reason Ruber recommends here Softlayer rest call giving multiple entries for invoice in json response when object filter is applied to relational properties use some programming language in order to retrieve all data you required:

Basically you need to do the following:

Step 1: Get all invoices by using SoftLayer_Account::getInvoices, based on you requirements it should be something like this:

https://api.softlayer.com/rest/v3/SoftLayer_Account/getInvoices?objectFilter={"invoices":{"createDate":{"operation":"betweenDate","options":[{"name":"startDate","value":["03/25/2017 00:00:00"]},{"name":"endDate","value": ["04/24/2017 23:59:59"]}]},"typeCode":{"operation":"RECURRING"}}}&objectMask=mask[id,createDate]

This will return the ID of all invoices, you will need this in the following step

Step 2: For each retrieved invoice use the method SoftLayer_Billing_Invoice::getItems, use resultLimits and your mask as following.

https://api.softlayer.com/rest/v3/SoftLayer_Billing_Invoice/[invoiceId]/getItems?resultLimit=100,0&objectMask=mask[id,recurringFee,recurringTaxAmount,oneTimeFee,oneTimeTaxAmount,description,hostName,domainName,hourlyRecurringFee,laborFee,laborTaxAmount,setupFee,setupTaxAmount,category[name],location[longName],billingItem[id,activeFlag,hourlyFlag,allowCancellationFlag,cancellationDate,orderItem[id,order[id,userRecord[id,username]]]]]

Change [invoiceId] by each ID you retrieved in the step 1.

On this case you need to use loops, the first loop to call SoftLayer_Billing_Invoice::getItems for each invoice and the second loop to retrieve items 100 by 100.(Instead of 100 you can set another value in resultLimit parameter)

If you set resultLimit=100,1 it will return all items between 101 to 200. I suggest to review https://sldn.softlayer.com/article/using-result-limits-softlayer-api

I recommend to use languajes like Python, Java, Go, Ruby, etc. You can see the list here https://sldn.softlayer.com/article/softlayer-api-overview.

Note: Unfortunately the object-filters feature is not supported by SoftLayer Java API.

I hope this help you.

Regards,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...