cancel
Showing results for 
Search instead for 
Did you mean: 
Machine Learning
cancel
Showing results for 
Search instead for 
Did you mean: 

Query ML Endpoint with R and Curl

BogdanV
New Contributor III

I am trying to get a prediction by querying the ML Endpoint on Azure Databricks with R. 
I'm not sure what is the format of the expected data. Is there any other problem with this code?

R Code.png

Thanks!!!

 

1 ACCEPTED SOLUTION

Accepted Solutions

BogdanV
New Contributor III

Hi Kaniz, 

I was able to find the solution. You should post this in the examples when you click "Query Endpoint"
You only have code for Browser, Curl, Python, SQL. You should add a tab for R
Here is the solution:

library(httr)
url <- "https://adb-********.azuredatabricks.net/serving-endpoints/********/invocations"
db_token="dap*******"
headers <- add_headers('Authorization'==paste('Bearer', db_token, sep=' '),
"Content-Type" = "application/json")

data='{"dataframe_split": {"columns": ["***columnName1String***", "***ColumnName2Integer****"], "data": [["val11", val12], ["val21", val22], ["val31", val32]]}}'
response= POST(url,headers,body=data)
results <- content(response, "parsed")

View solution in original post

3 REPLIES 3

Kaniz
Community Manager
Community Manager

Hi @BogdanV, Please paste the code stack here.

BogdanV
New Contributor III

Hi Kaniz, 

I was able to find the solution. You should post this in the examples when you click "Query Endpoint"
You only have code for Browser, Curl, Python, SQL. You should add a tab for R
Here is the solution:

library(httr)
url <- "https://adb-********.azuredatabricks.net/serving-endpoints/********/invocations"
db_token="dap*******"
headers <- add_headers('Authorization'==paste('Bearer', db_token, sep=' '),
"Content-Type" = "application/json")

data='{"dataframe_split": {"columns": ["***columnName1String***", "***ColumnName2Integer****"], "data": [["val11", val12], ["val21", val22], ["val31", val32]]}}'
response= POST(url,headers,body=data)
results <- content(response, "parsed")

Kaniz
Community Manager
Community Manager

Hi @BogdanV

Thank you so much for sharing your solution! We greatly appreciate your input. I'm glad to hear that you were able to find a solution that works for you.

If you have any more questions or need further assistance, please don't hesitate to reach out. We're here to help!

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.