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.

  1. 'use strict';
  2. ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
  3. function initializePage() {
  4. var siteURL;
  5. // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
  6. $(document).ready(function() {
  7. var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
  8. CreateListItem();
  9. });
  10. //Retrieve list items from sharepoint using API
  11. function CreateListItem() {
  12. siteURL = _spPageContextInfo.webAbsoluteUrl;
  13. console.log("from top nav - " + siteURL);
  14. var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items";
  15. $.ajax({
  16. url: apiPath,
  17. type: "POST",
  18. headers: {
  19. Accept: "application/json;odata=verbose"
  20. },
  21. data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:”Ur input "
  22. }
  23. ",
  24. async: false, success: function(data) {
  25. alert("Item is Created successfully!!");
  26. }, eror: function(data) {
  27. console.log("An error occurred. Please try again.");
  28. }
  29. });
  30. }
  31. }

Summary

In this blog, we have explored how to create an item in the SharePoint list using REST API. Happy Coding!!