How to Convert MS SharePoint $metadata XML Response into Standard Odata JSON in NodeJS?

814 Views Asked by At

I am working on MS SharePoint 2013 integration and in my use case I want to work on JSON data only.
I am able to convert all the API XML responses like File, Folder, List, ListItem, etc into OData JSON using Node Module - datajs_vanilla, but I am not able to convert https://mysite/_api/$metadata into OData JSON. I am getting below error while executing datajs for $metadata endpoint:

error:{"message":"no handler for data"} 

Below is my code snippet:

OData.read({
        requestUri: 'https://example.com/_api/$metadata',
        headers: {
                    'Authorization': 'Bearer token_value',
                    'Accept':'application/xml;charset=utf-8' 
                 } 
        }, function (data, response) {
            console.log("Operation succeeded."+JSON.stringify(data));
    }, function (err) {
        console.log("Error occurred " + JSON.stringify(err));
});

I am missing something here to convert into JSON?
or
Could you please suggest me possible solution to convert edmx sharepoint $metadata XML response into OData JSON using node module?

Thanks.

1

There are 1 best solutions below

5
On

See answer for similar question Get OData $metadata in JSON format .

Metadata document is not defined using OData atom/xml format that's why datajs vanilla is failing to parse it. Metadata format is CSDL format. Example of metadata doc - http://services.odata.org/V4/TripPinServiceRW/$metadata.

Usually metadata used for discovery and client generation since it has type info and all entity relations. Having service responses being serialized to json and service documentation in json should be sufficient for you to work with service.