0

I know JSON is the returned value structure from REST calls but I want to go the other way... I want to create a list from a JSON blob using REST. Is it possible?

Edit 1: I was pretty vague above so let me elaborate. What I'm asking is could I query a source with REST (doesn't have to be SharePoint; could be anything with a REST endpoint), save its raw JSON, and then turn around and run some JavaScript to create a SharePoint list based on the original list's JSON (complete with site columns and data)?

I expect to have to massage the JSON into a SharePoint-ready format and I know I could hack out an iterator where I send a REST POST to make a list, send more POSTs to make each column, and then yet more iterations for populating data... but I'm just curious if there is even a RESTful way to import JSON as a complete SP list in one swoop.

1

Assuming your json blob has all the required information and you use the right endpoint, sure it could work, but you'd have to parse the blob content and feed it into the request potentially.

jQuery.ajax({
        url: "http://<site url>/_api/web/lists",
        type: "POST",
        data:  JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true,
 'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }
),
        headers: { 
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "content-length": <length of post body>,
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: doSuccess,
        error: doError
});

https://msdn.microsoft.com/en-us/library/office/jj164022.aspx?f=255&MSPPError=-2147217396

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.