Error in metadata type when I try to do POST

0

I have this code:

function insertuser(obj){
        var listID = obj.getAttribute('data-listid'),
            itemID = obj.getAttribute('data-itemid'),
            URLID = obj.getAttribute('data-itemurl');

        var UserId = _spPageContextInfo.userId;

        var returl = URLID;
        var res1 = returl.substring(0,62);
        var REGEX = /.*\/Normativo\/(.+?)\/.*/;
        var res2 = returl.replace(REGEX, "$1");

        var res3 = res1.concat(res2);

        jQuery.ajax({
            url: res3 + "/_api/web/lists('" + listID + "')/items('" + itemID +"')?$select=ID,Title,QuemLeu/Id&$expand=QuemLeu",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose" 
            },
            success: function (data) {

                var userIdArray = [];
                if(data.d){
                    if(data.d.QuemLeu.results) {
                        for (var i = 0; i < data.d.QuemLeu.results.length; i++) {
                            userIdArray.push(data.d.QuemLeu.results[i].Id);
                        }
                    }
                }
                userIdArray.push(UserId);
                var fields = {
                    "__metadata": { 'type': "SP.Data.PaginasItem"},
                    "QuemLeuId": {"results": userIdArray  }
                }
                updateItem(fields);
            }, 
            error: function (error) {
                console.log(error);
            }
        });


        function updateItem(fields) {
            jQuery.ajax({  
                url: res3 + "/_api/web/lists('" + listID + "')/items('" + itemID +"')",  
                type: "POST",
                    data: JSON.stringify(fields),  
                    contentType: "application/json;odata=verbose",
                    headers: {  
                        "Accept": "application/json;odata=verbose",
                        "X-RequestDigest" : document.getElementById("__REQUESTDIGEST").value,
                        "X-HTTP-Method": "MERGE",
                        "If-Match": "*"  
                    },  
                success: function(data) {  
                   console.log("OK POST");
                   alert("OK POST");
                },  
                error: function(error) {  
                    console.log("ERRO POST");
                    console.log(JSON.stringify(error));  
                }  
            });
        }
    }

When running, give me this error:

This code is being used for items that are stored in Sharepoint Pages and in a document library. The code works correctly for the Pages list, but for the non-document library. I have already seen the ListItemEntityTypeFullName from the Pages list and it is SP.Data.PaginasItem but it seems the ListItemEntityTypeFullName does not work for document libraries. What should I do to make it work for both Pages for Document Library?

    
asked by anonymous 02.01.2019 / 15:37

0 answers