2

I try adding list item using REST in SharePoint 2013. when code is try add new item in list , getting error :

"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
  "message":
     {"lang":"en-US","value":"A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected."}}}"

My code

var addNewTask = function() {

    var data = {
        __metadata: {
            'type': 'SP.Data.Asana2ListItem'
        },
        Title: "dd",
        PriorityCod: "1",
        Category: "1",
        Desc2: "dd",
        AssignedTo: "Lynda",
        CONTRACT_HDR_ID: "1"
    };

    //console.log(tsk.AssignedUserId);
    //kkk
    var hostweburl =
        decodeURIComponent(
            getQueryStringParameter("SPHostUrl")
        );
    var appweburl =
        decodeURIComponent(
            getQueryStringParameter("SPAppWebUrl")
        );
    var scriptbase = hostweburl + "/_layouts/15/";

    // Load the js files and continue to the successHandler
    $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);

    function execCrossDomainRequest() {
        // executor: The RequestExecutor object
        // Initialize the RequestExecutor with the add-in web URL.
        var executor = new SP.RequestExecutor(appweburl);
        executor.executeAsync({
            url: appweburl +
                "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Asana2')/items/?@target='" +
                hostweburl + "'",
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
                "content-Type": "application/json;odata=verbose"
            },
            "X-HTTP-Method": "POST",
            "content-length": 50,
            "If-Match": "*",
            data: JSON.stringify(data),
            success: successHandler1,
            error: errorHandler1
        });
    }

    function successHandler1(data) {
        console.log(data);
    }

    function errorHandler1(data, errorCode, errorMessage) {
        console.log(data);
    }

Need help. I am new to sharepoint

4

2 Answers 2

5

Since you are using RequestExecutor, I think you are looking for body instead of data. Try replacing data: JSON.stringify(data) with body:JSON.stringify(data).

0
1

Try replacing data: JSON.stringify(data) with body:JSON.stringify(data).

This worked for me.

thank you.

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.