API Library add external file

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>>


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  
	a = Split(restReq.responseText,chr(34))
	access_token = a(3)
	if(access_token = "message") Then
	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  
		AddImageToXibo = response
End if

End Function

I believe it should be files

I don’t think I see any other obvious mistakes there, could you please try with files there and see if it will work for you?

Thanks peter; but sadly

changing to

strJSONToSend = “{”“files”":[{"“name”":"“API%20UPLOAD99"”,"“type”":"“files”","“src”":"“C:/\Users/\hans/\Pictures/\aftermarket.png”"}]}"

still gives error

“{“files”:[{“name”:“1506624315-5322”,“size”:103,“type”:“application/json”,“error”:“Filetype not allowed”}]}”

Can you help?

Shouldn’t that be form-data instead?

I’m not sure then, as far as API is concerned files is the only required parameter in this call.

I wonder if it would be easier for you in a long run to use oauth2 and our wrappers for that, alternatively perhaps look here as well