1

Good Morning

I have SharePoint page and library which holds some files.

This files are displayed there.

Is there good way to use WebServices to get the all items from this library using VBS?

Which webService methood would be the best for that.

Thanks

3
  • I need this to get all library items content. Lets say we have library and some files inside of this. Each of this files has status like "New, Printed, Sent" So I would like to update this statuses later.
    – Odyn
    Nov 25 '19 at 7:55
  • What is the purpose of using VBS
    – Milind
    Nov 26 '19 at 12:08
  • Looking on the solution which we are using, we have to use VBS for that
    – Odyn
    Nov 26 '19 at 13:27
0

Use SharePoint REST API. You will find complete documentation for rest api over here https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-rest-requests

Try:

Dim a As New MSXML2.ServerXMLHTTP60

a.Open "GET", url, False

Be sure to add reference to "Microsoft XML, v6.0"

20
  • Is it works also inside Visual Basic Script? Or only inside Visual Basic
    – Odyn
    Nov 26 '19 at 14:18
  • It will also work in VBS
    – Milind
    Nov 27 '19 at 5:20
  • Thanks. I am allso curious, is it right that I need to be Site Collection Administrator to perform some requests?
    – Odyn
    Nov 29 '19 at 7:36
  • It is not require to be Site Collection Admin but you should have permission to read permission to fetch list
    – Milind
    Nov 29 '19 at 7:37
  • Ok. Which web service can be used to fetch the list of files inside Library? Previously I was using list (status list) and now I need to get current files from library folder. Could You please tell me which web service can be used?
    – Odyn
    Nov 30 '19 at 7:45
1

Ok I found they way how it should be done to perform update:

  1. First we need to get item ID (like which one we want to update)
  2. We need to get SharePoint Request Diguest Token from sharepoint context api
  3. Later we need to use POST methood with MERGE like that:

    Dim updateURL, updateBody, requestUpdater, userName, userPassword
    
    Set requestUpdater = CreateObject("MSXML2.ServerXMLHTTP")
    
    userName = "login"
    userPassword = "password"
    
    requestURL = "https://share.point.site.url.com/_api/web/lists/getbytitle('ListName')/items(<ID>)"
    
    body = "{ '__metadata': { 'type': 'SP.Data.ListName' }, 'DescriptionField':'"& description &"' }"
    
    With requestUpdater
            .Open "POST", updateURL, False, userName, userPassword
            .setRequestHeader "Accept", "application/json;odata=verbose"
            .setRequestHeader "X-RequestDigest", token
            .setRequestHeader "Content-Type", "application/json;odata=verbose"
            .setRequestHeader "IF-MATCH", "*"
            .setRequestHeader "X-Http-Method", "MERGE"
            .send body
    End With
    

Its done in VB Script, but maybe someone will search for solution like that.

0

This is what I am already doing inside my VBS script:

Retriving item from library based on his CASE ID.

Option Explicit

Dim restOBJ, url, userName, password, domain

Set restOBJ = CreateObject("Microsoft.XMLHTTP")

url = "https://teams.sharepoint.com/cs/TestPage/_api/web/lists/getbytitle('TestLibrary')/items?$filter=CaseID eq '1234567'

restOBJ.open "GET", url, False
restOBJ.send

Watch.setVariable "XMLResponse", restOBJ.responseText

Can You please tell me how to update item?

2
  • I would like to update this particular item with this Case ID to change their Status field.
    – Odyn
    Dec 5 '19 at 10:01
  • So inside request which I get I have my item (file from library) and I would like to update item property <Task_x0020_Status> from "Open" to "Completed"
    – Odyn
    Dec 5 '19 at 10:13
0

This is what I have for now:

Dim restUPDATE, siteURL, restBODY

Set restUPDATE = CreateObject("Microsoft.XMLHTTP")

siteURL = "http://site url/_api/web/lists(guid'list GUID')" // url to to sharepoint list

// the metadata type of list from XML response
// Field Task_x0020_Status updated to 'Updated'
restBODY = "{ '__metadata': { 'type': 'SP.Data.ListName' }, 'Task_x0020_Status': 'Updated' }"

With restUPDATE
    .Open "POST", siteURL, False
    .setRequestHeader "accept", "application/json;odata=verbose"
    .setRequestHeader "Content-Type", "application/json;odata=verbose"
    .send restBODY
End With


Watch.setVariable "XMLResponse", oHttp.responseText "Updated correctly"

Not sure if its right yet, because lost access to machine when testing that. What do You think?

It will update all items from list?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.