Pnpjs: Create list item across site collection

Created on 23 Jul 2019  路  4Comments  路  Source: pnp/pnpjs

Need to create list items in List present in different site collection using pnp js

$.ajax({
url: otherSiteUrl + "/_api/contextinfo",
type: "POST",
headers: {
"Accept": "application/json;odata=verbose"
},
success: function (contextData) {
$.ajax({
url: otherSiteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items? @target ='" + otherSiteUrl + "'",
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(contextData.d.GetContextWebInformation.FormDigestValue)
},
success: function (data) {
alert('success');
},
error: function (jqXHR, textStatus, errorThrown) {
alert('error');
}
});
},
error: function (jqXHR, textStatus, errorThrown) {
alert('error');
}
});
the above is Rest Sample,kindly provide equivalent for Pnp Js

code answered question

All 4 comments

馃槺 Please, please, please! Read docs first before asking a question. In docs.

Sorry,i come across the web object(i already read the documents what here u mentioned) but i have some doubts in that,if get operation its work fine,but for post operation its need page context from form digest right??

Digests might be omitted, we manage them automatically in core fetch calls.

Oh thank u for ur patience and help

Was this page helpful?
0 / 5 - 0 ratings