Hi, I am writing a vbscript to upload a picture using teh XIBO api> The request works fine in postman, but I need the syntax and code in VBscript to upload the file.
Below what I have come up with;But I keep getting the response “Filetype not allowed”
Any help out there?
Public xibo_token, XiboEndpoint, client_id, client_secret, jsonText, ObjFSO, objLog
'Xibo properties
mainurl = <<URL.XIBO.Cloud>>
clientId = <<ID>>
clientSecret = <<SECRET>
access_token= <<TOKEN>>
requestXiboToken
AddImageToXibo
Function requestXiboToken
Dim restReq
Set restReq = CreateObject ("Msxml2.XMLHttp.6.0")
url = mainurl & "/api/authorize/access_token"
'---- Set url
restReq.open "POST", url , False
'---- Create headers
restReq.setRequestHeader "content-type", "application/x-www-form-urlencoded"
'---- Send request
restReq.send("client_id=" & clientId & "&client_secret=" & clientSecret & "&grant_type=client_credentials")
'---- Output response
If Err.Number <> 0 Then
Quit
Else
a = Split(restReq.responseText,chr(34))
access_token = a(3)
if(access_token = "message") Then
Quit
End If
End If
End Function
Function AddImageToXibo
Dim objXmlHttpMain , URL
strJSONToSend = "{""files"":[{""name"":""API%20UPLOAD99"",""type"":""file"",""src"":""C:/\Users/\hans/\Pictures/\aftermarket.png""}]}"
url = mainurl & "/api/library"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer " & access_token
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"
objXmlHttpMain.send strJSONToSend
response = objXmlHttpMain.responseText
set objJSONDoc = nothing
set objResult = Nothing
'---- Output response
If Err.Number <> 0 Then
Quit
Else
AddImageToXibo = response
End if
End Function