R API Run API token not accepted
Hello the code below run sucessful two times and the problem are on the dashboard. Why is the access with the token is now not permitted to run other problems or to get the answer?
library(httr)
library(magrittr)
require(jsonlite)
# api token
sapi_token <- "DEV-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# problem id
id <- "613a145a-1813-447b-a616-10531c621c06"
# home
sapi_home <- "https://cloud.dwavesys.com/sapi"
# header
h <- add_headers("X-Auth-Token" = sapi_token)
# solver path
solvers_remote <- paste(sapi_home,"/solvers/remote", sep="")
# get the information for the solver
jsonRespText <- GET(solvers_remote, h) %>%
content( as="text")
jsonRespText
# problem path
solvers_problems <- paste(sapi_home,"/problems", sep="")
# header
params <- list(num_reads=123)
args <- list(solver="DW_2000Q_2_1",
data="128 3\n48 48 -1\n52 52 1\n48 52 -1",
type="ising",
params = params
)
# curl api post
res <- POST(
url = solvers_problems,
h,
body = toJSON(args)
)
# print the result
jsonRespParsed<-content(res,as="parsed")
jsonRespParsed
# get the answer to the solved problem
res1 <- GET(paste(solvers_problems, "/?id=613a145a-1813-447b-a616-10531c621c06", sep=""), add_headers("X-Auth-Token" = sapi_token))
# print the answer
jsonRespParsed<-content(res1,as="text")
jsonRespParsed
The output was:
library(httr) > library(magrittr) > require(jsonlite) > > # api token > sapi_token <- "DEV-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" > > # problem id > id <- "613a145a-1813-447b-a616-10531c621c06" > > # home > sapi_home <- "https://cloud.dwavesys.com/sapi" > > # header > h <- add_headers("X-Auth-Token" = sapi_token) > > # solver path > solvers_remote <- paste(sapi_home,"/solvers/remote", sep="") > > # get the information for the solver > jsonRespText <- GET(solvers_remote, h) %>% + content( as="text") No encoding supplied: defaulting to UTF-8. > jsonRespText [1] "[{\"status\": \"ONLINE\", \"description\": \"D-Wave 2000Q System\", \"avg_load\": 1.0, \"id\": \"DW_2000Q_2_1\", \"properties\": {\"chip_id\": \"DW_2000Q_2_1\", \"num_qubits\": 2048, \"num_reads_range\": [1, 10000], \"max_anneal_schedule_points\": 4, \"anneal_offset_step\": 0.004266738445272551, \"programming_thermalization_range\": [0, 10000], \"parameters\": {\"reduce_intersample_correlation\": \"A boolean for whether to add pauses between samples.\", \"num_spin_reversal_transforms\": \"\", \"programming_thermalization\": \"An integer that gives the time (in microseconds) to wait after programming the processor in order for it to cool back to base temperature..\", \"reinitialize_state\": \"Whether to reapply the initial_state for every read.\", \"anneal_offsets\": \"A list of anneal offsets for each working qubit (NaN if unused).\", \"num_reads\": \"\", \"max_answers\": \"\", \"readout_thermalization\": \"An integer that gives the time (in microseconds) to wait after each state ... <truncated> > > # problem path > solvers_problems <- paste(sapi_home,"/problems", sep="") > > # header > params <- list(num_reads=123) > args <- list(solver="DW_2000Q_2_1", + data="128 3\n48 48 -1\n52 52 1\n48 52 -1", + type="ising", + params = params + ) > > # curl api post > res <- POST( + url = solvers_problems, + h, + body = toJSON(args) + ) > > # print the result > jsonRespParsed<-content(res,as="parsed") > jsonRespParsed $`error_code` [1] 404 $error_msg [1] "Solver does not exist or apitoken does not have access" > > # get the answer to the solved problem > res1 <- GET(paste(solvers_problems, "/?id=613a145a-1813-447b-a616-10531c621c06", sep=""), add_headers("X-Auth-Token" = sapi_token)) > > # print the answer > jsonRespParsed<-content(res1,as="text") No encoding supplied: defaulting to UTF-8. > jsonRespParsed [1] "Problem does not exist or apitoken does not have access"
Comments
Hello again Eric,
Just reading through your question again - how is the code failing? Could you post the error response?
Hi Luca,
I figured it out, the API token has no access, I get the same message with curl.
the output error response:
jsonRespParsed $`error_code` [1] 404 $error_msg [1] "Solver does not exist or apitoken does not have access"
jsonRespParsed [1] "Problem does not exist or apitoken does not have access"
Hello Eric,
The two successful problems you posted (from February 27) may be from running a Leap demo. These problems are not processed with your developer token, so this would explain why you cannot access the solved problem.
I am still not sure why your POST request does not work. I have only been able to reproduce a 404 error when I enter a bad solver name (for example "DW_2000Q_1").
One more thought: I'm guessing from your code that you prefer working in R, but it might help to troubleshoot your connection to the D-Wave QPU if you installed the Ocean SDK (written in Python):
Hello Luca,
the ping command works fine from within the
and also the problems are listed in the dashboard.
Thank you
Is the C++ library as advanced as the python sdk or are there some extras? Yes, I might prefer C++ as well. Thanks for your help
There is still the option to write a R package for the C++ library to use with the API as you know of course. All are good.
Hello Eric,
Since you are able to ping D-Wave with dwave-ocean-sdk and the problems appear in the dashboard, your API token seems to be working properly. The errors you are seeing could be because of the formatting of the POST request. I would suggest checking how these requests look before sending to D-Wave's endpoint.
Unfortunately, D-Wave's Ocean SDK is only available in Python - we do not currently have a C++ library available for Leap users.
Hi Eric,
I was just looking at this and noticed that you might need an encoding statement, since you are using json.
res <- POST(
url = solvers_problems,
h,
body = toJSON(args),
encode = "json"
)
Hopefully this will help you debug your R implementation
Hi Luca, thank you.
Please sign in to leave a comment.