Create Item in SharePoint 2019 list from external website.

Sachin Soni 26 Reputation points
2021-09-30T07:18:53.83+00:00

Dear Experts,

I have SharePoint 2019 On premise site and i want to create an item in SharePoint List from external website (External website has custom html/JS forms) from which user submit the item and i want to store this information in my sharepoint 2019 list.

How can we achieve this, kindly help.

Note : I don't have Power Automate and Azure Option

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,238 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,694 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,576 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Sharath Kumar Aluri 3,071 Reputation points
    2021-09-30T16:55:57.957+00:00

    You can use the SharePoint Rest API option, below article for your reference.

    function addListItem() {
                   var myListUrl= "mysite.sharepoint.com/_vti_bin/listdata.svc/myList";    
                   var item= {};
                   item.Title = "Adding an item using 2010 REST API";
    
                   var itemEntry= JSON.stringify(item);
    
                   $.ajax({
                       type: "POST",
                       url: myListUrl,
                       data: itemEntry,
                       contentType: "application/json; charset=utf-8",
                       success: function () {
                           //do stuff here
    
                       },
    
                      error: function() {
                         //do some error handling here
                      }
    
                   });
               }
    

    https://stackoverflow.com/questions/36727356/write-to-a-sharepoint-list-from-an-html-page-that-is-not-located-within-the-shar

    Thanks & Regards,

    1 person found this answer helpful.

  2. MichaelHan-MSFT 18,016 Reputation points
    2021-10-01T04:09:05.4+00:00

    Hi @Anonymous ,

    You need to consider cross-domain issues to call SharePoint rest-api from external site. There are a few approaches to solve this:

    • CORS (Cross-origin resource sharing)
    • JSONP (JSON with padding)
    • IFrame with PostMessage API

    Please refer to this article for more information:

    https://www.vlieshout.net/how-to-gather-data-from-sharepoint-using-rest-api-on-external-website/

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. sadomovalex 3,626 Reputation points
    2021-10-05T14:23:11.777+00:00

    if you want to save request from javascript you will need to solve problem with CORS (I assume that external site and Sharepoint site use different domain names). There is simpler option but it will require adding server-side code to your external site: e.g. you may add .ashx handler (it will work for sites created in ASP.Net), call this handler from javascript (there won't be CORS issues because ashx handler and javascript code will run on the same domain), from ashx handler add item to external Sharepoint list using C# and CSOM. For authentication you may use app-only permission (based on client id and secret).