-1

When calling an REST API method I get back that there is an error

Error processing request stream. The payload must represent a valid array format for collections.

But when searching for:

valid array format for collections

I get back a lot, but nothing clarifies what is meant by this. I'm guessing the data i send is not valid (currently i'm sending an array('foo' => 'Bar')) but this is probably not correct.

Has anybody got a pointer to what is happening here? Or what i could check?

The documentation of ExactOnline (which I'm posting to) is not sufficient. It only states what fields they have, but nothing about these kind of error messages.

==========================

Ok, this needs some clarification, my bad!

As written, i'm communication with ExactOnline, via their API.

I'm calling the method to post a sales order. With that, i'm using a set of scripts Exact provides on their website (for developers).

on page: https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=SalesOrderSalesOrders

under 'POST', you can read the mandatory fields, under which 'SalesOrderLines' is one of them. It does not tell me what it expects or in what format.

I wrapped my array in a json_encode and tried again, but no luck. It still tells me the same error.

Guido Leenders
  • 4,232
  • 1
  • 23
  • 43
Tijn Snijders
  • 83
  • 1
  • 8

2 Answers2

3

I'am currently using the same ExactOnline API. Have to say that the documentation lacks in information on this topic indeed!

To make a valid array for collections you have to use the following base:

$array = array(
   'InvoiceTo' => 'bc960e43-be9d-409c-9cfe-31ce56cc3238',
       'SubscriptionLines' => array(
           array('Item' => '7e50702b-5bbf-4b77-ab73-5dad50016e82')
       )
)

The json_encode($array) on this list would be:

{
"InvoiceTo":"bc960e43-be9d-409c-9cfe-31ce56cc3238",
    "SubscriptionLines":[
        {"Item":"7e50702b-5bbf-4b77-ab73-5dad50016e82"}
    ]
}

So the important part here is to do array(array()) inside the SubScriptionLines. This tells the JSON that you want to use an JSON Array instead of the JSON Object notation.

For your particular question you need to change the keys into the keys given in the documentation for a SalesOrder. Not all manditory fields of the api are included here, because this solution is for Subscriptions. However, the principle will be the same.

Hope this will help you and others implementing the exact API fully :)

David Kooijman
  • 632
  • 3
  • 18
1

How are you serializing your payload? If it is meant to be in JSON format, a collection would look like this:

[
    {
        "foo": "bar"
    },
    {
        "foo": "baz"
    }
]
Aykut Çevik
  • 2,060
  • 3
  • 20
  • 27
  • The description of the field only tells me this: "Collection of lines".. I;m not sure if i need to send an actual collection of whatever, or what have you... a uuid? – Tijn Snijders Dec 03 '15 at 20:24