Serialization of batches of type complex is not supported?

Apr 19, 2011 at 8:41 PM
Hi,
When trying to POST a batch I get the following error:

	"Serialization of batches of type complex is not supported"

The code I'm using to post the batch is as follows. I have included in the function a single POST which is successful

       function CreateInvoice() {
            var invoice = { "SecondReference": "00000909", "TransactionReference": "INV00003", "GoodsValueInAccountCurrency": "236", "TransDateAsString": "07/04/2011" };
 
            OData.request(
            {
                headers: { Accept: "application/json" },
                requestUri: "http://localhost:52731/PurchaseService.svc/PLPostedSupplierTrans",
                method: "POST",
                data: invoice
            },
            function (value, response) {
                alert("Single Post Successful");
            },
            function (err) {
                alert("Error occurred " + err.message);
            });
 
            OData.request(
            {
                headers: { Accept: "application/json" },
                requestUri: "http://localhost:52731/PurchaseService.svc/$batch",
                method: "POST",
                data: { _batchRequests: [
                      { _changeRequests: [
                        { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice },
                        { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice }
                      ]
                      }
                      ]
                }
            },
            function (value, response) {
                alert("Batch Post Successful");
            },
            function (err) {
                alert("Error occurred " + err.message);
            }, OData.batchHandler);
 
        }
Can anyone shed any light?
Thanks
Apr 19, 2011 at 9:41 PM
Edited Apr 20, 2011 at 12:17 AM

Hi scottseanjack,

The problem is that you are missing an underscore ( _ ) in the _batchRequests and _changeRequests identifiers. Instead of

OData.request(
{
    headers: { Accept: "application/json" },
    requestUri: "http://localhost:52731/PurchaseService.svc/$batch",
    method: "POST",
    data: { _batchRequests: [
                 { _changeRequests: [
                     { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice },
                     { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice }]
                  }]
    }
},
function (value, response) {
    alert("Batch Post Successful");
},
function (err) {
    alert("Error occurred " + err.message);
}, OData.batchHandler);

It should be

OData.request(
{
    headers: { Accept: "application/json" },
    requestUri: "http://localhost:52731/PurchaseService.svc/$batch",
    method: "POST",
    data: { __batchRequests: [
                 { __changeRequests: [
                     { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice },
                     { requestUri: "PLPostedSupplierTrans", method: "POST", data: invoice }]
                  }]
    }
},
function (value, response) {
    alert("Batch Post Successful");
},
function (err) {
    alert("Error occurred " + err.message);
}, OData.batchHandler);

You can get more details about the library's payload formats here.



Regards,

Alex Trigo.

Apr 19, 2011 at 11:02 PM

Doh...Thanks Alex and thanks for the link