Home > Blockchain >  AzureCognitive R package translate service returns http 400: "body of request is not valid JSON
AzureCognitive R package translate service returns http 400: "body of request is not valid JSON

Time:11-12

I've tried to get the translate service to work using the AzureCognitive R package, but I get a HTTP 400 error and I can't seem to fix it.


# Initial setup
# I've already did the create login
# az <- AzureRMR::create_azure_login(tenant = "<tenant>")

az <- AzureRMR::get_azure_login()
sub <- az$get_subscription(id = "<id>")
rg <- sub$get_resource_group("<resource-group>")

# retrieve it
cogsvc <- rg$get_cognitive_service(name = "<name>")

# getting the endpoint from the resource object
endp <- cogsvc$get_endpoint()


############################
# This is where it fails
############################

call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = "[{'Text':'Hello, what is your name?'}]",
                        http_verb = "POST")


call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = list(text = "Hello, what is your name"),
                        http_verb = "POST")


Can someone see if this is a bug or me doing something wrong?

CodePudding user response:

As per this example, you can pass the body as body=list(list(text = "Hello, what is your name"")),

call_cognitive_endpoint(endpoint = endp,
                        operation = "translate",
                        options = list('api-version' = "3.0",
                                       'from' = 'en',
                                       'to' = 'dk'),
                        body = list(list(text = "Hello, what is your name")),
                        http_verb = "POST")

  • Related