IBM Watson API Test

I have been meaning to post something like this code for a while. Here is an example of calling one of the IBM watson API’s from a MRS script.  Its just code and i think easy to understand. The full API i am playing with can be found here. https://cloud.ibm.com/apidocs/language-translator#translate

Dim sUrl
Dim http
Dim apiHash

sUrl = "https://gateway-syd.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01"
set oHTTP = createObject("Microsoft.XMLHTTP")

oHTTP.open("GET", sUrl, false)
'The string after "Basic" is the base64 encoded of apikey:[YourAPIKEY]
'I.e.: apihash = Base64Encode("apikey:[YourAPIKEY]")

apiHash = "[YOURHASH]"
oHTTP.setRequestHeader("Authorization", "Basic " + apiHash)
oHTTP.setRequestHeader("content-type", "application/json")
oHTTP.send("{""text"":[""Hello""],""model_id"":""en-es""}")

If oHTTP.status = 200 Then
    debug.Log("RESPONSE : " + oHTTP.responseText)
else
    debug.Log("ERRCODE : " + ctext(oHTTP.status))
    debug.Log("RESPONSE : " + oHTTP.responseText)
End If
%d bloggers like this: