0
votes

I am Developing a plugin that exports Documents to SharePoint Repository after processing them. Along with the document, I need to send values for Custom Metadata columns defined in SharePoint.

I have figured out how to send across Files and Metadata to a specified location.

Problem: Initially, I do not know what custom metadata columns are available in the given folder. Could someone shed light on any REST webservice that can fetch the available Metadata Columns for a given location in the repository.

Note: I am using pure Java for REST Requests using Apache HTTP Client.

2

2 Answers

1
votes

The REST url for retrieving the custom fields in a list is:

_api/web/lists/GetByTitle('Custom List')/fields

I don't know much about parsing JSON in java but this will give you a list of all the columns and extensive details about them. I displayed some of the data returned below.

DefaultValue : null
Description : ""
EnforceUniqueValues : false
Id : "fa564e0f-0c70-4ab9-b863-0177e6ddd123"
Indexed : false
InternalName : "Title"
ReadOnlyField : false
Required : false
StaticName : "Title"
Title : "Title"
FieldTypeKind : 2
TypeAsString : "Text"
TypeDisplayName : "Single line of text"

If you need to get the available columns of a specific folder, and not a library:

_api/web/getfolderbyserverrelativeurl('/Shared%20Documents/Folder')/ListItemAllFields
0
votes

SharePoint 2013 has a REST API endpoint that could retrieve and filter Metadata columns if you obtain the information through a POST request using CAML. If your requests were made from SharePoint itself, you would use the masterpage's RequestDigest, but since you are doing it remotely, you would have to get this parameter by querying /_api/contextinfo and obtaining the FormDigestValue. Here is an article on it:

http://www.cleverworkarounds.com/2013/09/23/how-to-filter-on-a-managed-metadata-column-via-rest-in-sharepoint-2013/

Also, you must enable CORS on your SharePoint data repository.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
   <httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
     </customHeaders>
   </httpProtocol>
 </system.webServer>
</configuration>