Get All Content Types From Site in SharePoint using REST API

The example in this topic show how to use REST API to Get All Content Types From Site in SharePoint

  • function GetAllSiteContentTypes() {
  •  
  •     $.ajax
  •         ({
  •             // _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.
  •             // You can replace this with other site URL where you want to apply the function
  •  
  •             // Enter group Name over here
  •             url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/contenttypes",
  •             type: "GET",
  •             headers:
  •                {
  •                    // Accept header: Specifies the format for response data from the server.
  •                    "Accept": "application/json;odata=verbose"
  •                },
  •             success: function (data, status, xhr) {
  •                 var dataresults = data.d.results;
  •                 for (var i = 0; i < dataresults.length; i++) {
  •                     console.log("Conent Type Name - " + dataresults[i].Name);
  •                 } 
  •             },
  •             error: function (xhr, status, error) {
  •                 console.log("Failed");
  •             }
  •         });
  • }

Thank you for reading this article. This code was tested in SharePoint 2013


© 2019 Code SharePoint