Create folder inside channel of a Teams' team using Graph from VBA
Hello,
I'm trying to create a folder on a team's channel in Teams, using the Graph API inside VBA running in an Excel file. Basically, I have an excel file with data and a button, and when the button is pushed, it would trigger the creation of a folder inside a channel of a team. For this, I have registered an app and provide it with appropriate permissions and consent. I'm successful at retrieving an access token for the app, but the POST fails with error 500 (InternalServerError - Unable to find target address). Slight changes to the url (filesFolder » filesFolder:)may result in Status code 400. Here is the relevant code I'm using:
' Get access token using the fetched values
Dim accessToken As String
accessToken = GetAccessToken(clientId, clientSecret, tenantId)
Debug.Print "The access token is: " & accessToken
Dim url As String
Dim jsonBody As String
Dim xmlHttp As Object
Dim teamId As String
Dim channelId As String
teamId = Range("AS_QMS_TEAM_ID").Value
channelId = Range("AS_PCM_CHANNEL_ID").Value
' Construct the URL for the Graph API endpoint
url = "https://graph.microsoft.com/v1.0/teams/" & teamId & "/channels/" & channelId & "/filesFolder/children"
' The JSON body of the request
jsonBody = "{""name"": ""DRFQ-001"", ""folder"": {}}"
' Create an XMLHTTP object
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
' Open the request and set headers
xmlHttp.Open "POST", url, False
xmlHttp.setRequestHeader "Content-Type", "application/json"
xmlHttp.setRequestHeader "Authorization", "Bearer " & accessToken
' Send the request
xmlHttp.Send jsonBody
' Print status and response
Debug.Print "Status: " & xmlHttp.Status
Debug.Print "Response: " & xmlHttp.responseText
Actually, the end idea is to create a folder inside an existing folder but for now I would be happy to create it on the root folder of the channel... The problem is most probably on the request url but I'm too rookie on Graph to find it.
Any idea?
Thank you!
Inácio