Here is the detailed documentation for the lists and their features.
There are multiple ways to create a list item, here I’m sharing the REST API Code.
Steps to Create the SP List Item
Follow the below listed steps to Create an item.
Step 1
Create one JS file or you can use the Content Editor Web Part.
Step 2
Below is the API to get the particular list, you can browse this URL in the browser to check whether the API is working or not.
https://sharepoint.com/_api/web/lists/GetByTitle('samplelist')/items
Note
Replace your list name with “samplelist”.
Step 3
Refer to the jQuery in your HTML file or CEWP.
Use the below code to Create an item in a SharePoint list.
- 'use strict';
- ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
-
- function initializePage() {
- var siteURL;
-
- $(document).ready(function() {
- var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
- CreateListItem();
- });
-
- function CreateListItem() {
- siteURL = _spPageContextInfo.webAbsoluteUrl;
- console.log("from top nav - " + siteURL);
- var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items";
- $.ajax({
- url: apiPath,
- type: "POST",
- headers: {
- Accept: "application/json;odata=verbose"
- },
- data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:”Ur input "
- }
- ",
- async: false, success: function(data) {
- alert("Item is Created successfully!!");
- }, eror: function(data) {
- console.log("An error occurred. Please try again.");
- }
- });
- }
- }
Summary
In this blog, we have explored how to create an item in the SharePoint list using REST API. Happy Coding!!