I created a library that contains documents in Sharepoint Online. Let's call it myLib. I also created a content type, myCT. My objective is to retrieve informations concerning fields I created in a content type in sharepoint online. The library is using the content type i created.
For this i also created a webpart component that aims to generate a form with the content type fields / columns. I need to retrieve :
- the field name
- the field type
- the values (for select, radio buttons, checkboxes)
For this I found that i can access XML datas from sharepoint at this URI : https://myAppUrl.sharepoint.com/_api/web/
My issue is that I spent a rather long time trying to find where the data from the content type is stored. I tried those URLs :
- https://myAppUrl.sharepoint.com/_api/Web/ContentTypes
- https://myAppUrl.sharepoint.com/_api/Web/AvailableContentTypes
Without finding what i'm looking for. I also tried to create a script in the webpart: :
function getallContentTypes() {
var clientContext = SP.ClientContext.get_current();
oContentTypes = clientContext.get_web().get_contentTypes();
clientContext.load(oContentTypes);
clientContext.executeQueryAsync(
Function.createDelegate(this, function() {
var ctypesInfo = '';
var ctypesEnumerator = oContentTypes.getEnumerator();
while (ctypesEnumerator.moveNext()) {
var ocontentType = ctypesEnumerator.get_current();
ctypesInfo += '\n' + 'ContentType Title: ' + ocontentType.get_name()+'\t'+ ocontentType.get_id();
}
console.log(ctypesInfo.toString());
}),
Function.createDelegate(this, function() {
console.log('failed');
}));
}
function injectMethod(){
getallContentTypes();
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
it returned me information concerning the content type : ContentType Title: myCT 0x0101007D18D0E5D0A176498869E2673AD0CA14
Now i wish to know how to handle this.
UPDATE after FredericDietrich help : I tried to use URL like : _api/Web/ContentTypes?$select=Name,Id,StringId&$filter=Name eq 'myCT'
And i obtain an XML:
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xml:base="https://dsidiff365.sharepoint.com/_api/">
<id>c2f25390-1496-45f6-9c87-0f6c0a9ea026</id>
<title />
<updated>2019-11-27T15:54:07Z</updated>
<entry> <id>https://myurl.sharepoint.com/_api/Web/ContentTypes('0x010100ED0CEB986D733A47AD45D9A995911BAA')</id>
<category term="SP.ContentType" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/ContentTypes('0x010100ED0CEB986D733A47AD45D9A995911BAA')" />
<title />
<updated>2019-11-27T15:54:07Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:Id m:type="SP.ContentTypeId">
<d:Name>Facture</d:Name>
<d:StringId>0x010100ED0CEB986D733A47AD45D9A995911BAA</d:StringId>
</m:properties>
</content>
</entry>
</feed>
but no information concerning fields


