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?

613a145a-1813-447b-a616-10531c621c06
Wed, Feb 27, 2019 12:06 PM
12:06:13 PM
 
Completed
2c80ce15-1a16-46b6-87b0-326aef4be2b2
Wed, Feb 27, 2019 12:04 PM
12:04:42 PM
Completed
 
Thank you for your help
 
I modified the code like this:

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"

 

 

 

 

0

Comments

10 comments
  • Hello again Eric, 

    Just reading through your question again - how is the code failing? Could you post the error response?

    1
    Comment actions Permalink
  • 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"
    0
    Comment actions Permalink
  • 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").

    0
    Comment actions Permalink
  • 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):

    1. Install D-Wave Ocean Tools
    2. Configure your system with "dwave config create"
    3. Try "dwave ping" command to see if you are able to successfully connect to D-Wave
    0
    Comment actions Permalink
  • Hello Luca,

    the ping command works fine from within the

    dwave-ocean-sdk

    and also the problems are listed in the dashboard.

    Thank you

    0
    Comment actions Permalink
  • 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

    0
    Comment actions Permalink
  • 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.

     

    0
    Comment actions Permalink
  • 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.

    0
    Comment actions Permalink
  • 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

    0
    Comment actions Permalink
  • Hi Luca, thank you.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post