I have problem with connection to the Azure Cognitive Service Text API (here is documentation:) using HTTR.
library(httr)
library("XML")
api_url <- 'https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment'
mybody <-list('id'='1', 'text'= 'come on love boy', 'language'="en")
result = POST(api_url,body = mybody, content_type('application/json'),encode = "json", add_headers(.headers = c("Content-Type"='application/json',"Ocp-Apim-Subscription-Key"="XXX")))
result
Response [https://westcentralus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment]
Date: 2019-02-21 00:12
###correct status = 200
Status: 400
Content-Type: application/json; charset=utf-8
Size: 222 B
How shall I implement "text" into the body of the API query?
I found the solution:
write the body as:
mybody <-list('documents'= list(list('id'='1', 'text'= 'come on love boy', 'language'="en")))
Works.