Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Getting additional field names from document library queried by a CAML query

Open denicomp opened this issue 3 years ago • 0 comments

I want to get a list of files from a document library using a CAML query. This also needs to be recursive because the library contains many folders that have the files.

I can get this to work, but I need to get a URL to each of the files. However, when I use get_items(caml_query), it is not returning all of the fields on each file. It is returning:

FileSystemObjectType
Id
ServerRedirectedEmbedUri
ServerRedirectedEmbedUrl
ContentTypeId
ComplianceAssetId
Title,
MediaServiceImageTags
MediaServiceOCR
ID
Created
AuthorId
Modified
EditorId
OData__CopySource
CheckoutUserId
OData__UIVersionString
GUID

What I think I need is one of these: FileRef, ServerUrl, EncodedAbsUrl

How do I tell it to get the fields I want - I see examples of how to do it getting an individual file, but what about when you want all files found using a CAML query, without making a separate API call on every file returned?

My code is like this:

	sp_lists = ctx.web.lists
	doclib = sp_lists.get_by_title("Some Document Library")
	query_text = '''<View Scope='Recursive'><Query><Where>
        <Eq>
            <FieldRef Name='Project_x0020_ID' />
            <Value Type='Text'>ABC123</Value>
        </Eq>
       </Where></Query></View>
        '''
	caml_query = CamlQuery.parse(query_text)
        sel_items = doclib.get_items(caml_query).execute_query()

         for item in sel_items
              url = item.properties["ServerUrl"]      <<< KeyError 'ServerUrl'

denicomp avatar Jul 27 '22 03:07 denicomp