locked
REST API RRS feed

  • Question

  • I am unable to add list item in list using below code getting forbidden error . Please suggest.

    $.ajax({

                        url: queryUrl,

                        type:

    "POST",

                        contentType:

    "application/json;odata=verbose",

                        data: JSON.stringify(

                             {

                                

    '_metadata': { 'type': 'SP.ListItem'},

                                

    'CustomerName': customer,

                                

    'Location': location

                             }),

                        headers: {

                           

    "accept": "application/json;odata=verbose",

                           

    "X-RequestDigest": $("#_REQUESTDIGEST").val()

                        },          

                      

                        success: onQuerySuccess,

                        error: onQueryFailure

    Friday, June 19, 2015 5:29 AM

Answers

  • Hi,

    Continue to Sergion's suggestion, I suggest you can refer the code snippet like below:

    jQuery.ajax({
            url: "https://sjkpdemo.sharepoint.com/Access/_api/web/lists/getbytitle('test')/items",
            type: "POST",
            data:  JSON.stringify({ '__metadata': { 'type': 'SP.ListItem' }, 
      'Title': 'Test'}
    ),
            headers: { 
                "accept": "application/json;odata=verbose",
                "content-type":"application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function(d) {console.log(d);},
            error: function() {console.log('fail');}
    });

    Here is a detailed article for your reference:

    SharePoint 2013 working with rest

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, June 22, 2015 10:20 AM

All replies

  • Take a look at this...

    http://sharepoint.stackexchange.com/questions/114379/how-to-get-form-digest-value-used-in-rest-call

    The value of ("#_REQUESTDIGEST").val() is correct?

    Try debugging the page to check this value...


    Regards,
    Bubu
    http://zsvipullo.blogspot.it

    Please mark my answer if it helped you, I would greatly appreciate it.

    Friday, June 19, 2015 7:49 AM
  • Hi,

    Continue to Sergion's suggestion, I suggest you can refer the code snippet like below:

    jQuery.ajax({
            url: "https://sjkpdemo.sharepoint.com/Access/_api/web/lists/getbytitle('test')/items",
            type: "POST",
            data:  JSON.stringify({ '__metadata': { 'type': 'SP.ListItem' }, 
      'Title': 'Test'}
    ),
            headers: { 
                "accept": "application/json;odata=verbose",
                "content-type":"application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function(d) {console.log(d);},
            error: function() {console.log('fail');}
    });

    Here is a detailed article for your reference:

    SharePoint 2013 working with rest

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, June 22, 2015 10:20 AM