0

I'm getting continuous 403 forbidden errors when trying to add a list item. Here's what I have so far

 $.ajax({
            url: webUrl,
            type: "POST",
            contentType: "application/json;odata=verbose",
            data: JSON.stringify(item),
            headers: { "Accept": "application/json; odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val() },
            success: function (data) {
                success(data);
            },
            error: function (data) {
                alert("failure");
            }
     });
5
  • are you querying a separate domain/webapp? what version are you on?
    – Mike
    Oct 4 '17 at 18:07
  • i'm querying a list on sharepoint through a webapp located on sharepoint. using 2013 sharepoint
    – azmatrix
    Oct 4 '17 at 18:08
  • is it across site collections?
    – Mike
    Oct 4 '17 at 18:10
  • Try to copy your webUrl and then paste in the browser and see if the endpoint is available. If you could share the URL whitout server address, only the REST endpoint would be useful too. Oct 4 '17 at 22:12
  • I’m not sure if it’s on site collections. How can I find out?
    – azmatrix
    Oct 5 '17 at 2:25
-1

try this

            $.ajax({
                url: webUrl + "/_api/lists/getbytitle('---ListName--')?$select=ListItemEntityTypeFullName",
                method: "GET",
                headers: { "Accept": "application/json;odata=verbose" },
                success: onEntitySuccess,
                error: onEntityFailure
            });
        function onEntitySuccess(data) {
            listItemEntity = data.d.ListItemEntityTypeFullName;
        }
        function onEntityFailure(err) {
            alert(err.statusText);
        }
7
  • is this to post?
    – azmatrix
    Oct 4 '17 at 18:24
  • what is this to post?
    – karthik
    Oct 4 '17 at 18:31
  • i'm trying to add a new list item. shouldn't that be post?
    – azmatrix
    Oct 4 '17 at 18:51
  • it for to add list item to list (
    – karthik
    Oct 4 '17 at 18:53
  • try by replacing you ajax call with this, hope it will work.
    – karthik
    Oct 4 '17 at 19:02
-1

try this

 try {
                    var queryUrl = Url + "/_api/lists/GetByTitle('--ListName--')/items";
                    $.ajax({
                        url: queryUrl,
                        type: "POST",
                        contentType: "application/json;odata=verbose",
                        data: JSON.stringify(
                            {
                                '__metadata': {
                                    'type': listItemEntity
                                },
                                'Name' : CTName,
                                'ListName': CTListName,
}),
                    headers: {
                        "accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val()
                    }, success: data,
                    error: data
                });
            }
            catch (ex) {
                alert("Exception" + ex.message);
            }
        }
2
  • This code doesn't even works, there a lot of sintaxe errors. Oct 4 '17 at 22:15
  • tell me those syntax errors ..?
    – karthik
    Oct 5 '17 at 12:10

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.