4
$\begingroup$

Want to use the API from this site. I'm having trouble using the same parameters.

But I can do this with curl as shown on the site:

curl 
  -F url=http://sbml.org/validator/api/sample-01.xml 
  -F output=xml 
  -F offcheck=u 
  http://sbml.org/validator/

But I can't get the same with Mathematica:

t1 = URLExecute @ HTTPRequest[
  "http://sbml.org/validator/"
, <|"Method" -> "POST"
  , "Headers" -> {
      "Content-Type" -> "multipart/form-data;"
    , "Expect" -> ""
    }
  , "MultipartElements" -> {
      {"name=\"url\";"} -> "http://sbml.org/validator/api/sample-01.xml"}
  |>
, CharacterEncoding -> None
];

ImportString[StringJoin[t1], "XHTML"]

OUTPUT

File : null
Options :
Units consistency checking: on Identifier consistency checking: on \
MathML consistency checking: on SBO consistency checking: on \
Overdetermined model checking: on Modeling practices checking: on \
Overall SBML consistency checking: on Remove unrecognized packages: \
on Results: No model was given or it could not be resolved.
$\endgroup$
1
  • 1
    $\begingroup$ Don't you need apikey? $\endgroup$ Commented Apr 10, 2018 at 6:48

1 Answer 1

1
$\begingroup$

Assuming you will get a valid apikey you can use x-www-form-urlencoded and a list of rules in the body to send a form. I'm not sure how to handle form-data type:

t1 = URLExecute @ HTTPRequest[
   "http://sbml.org/validator/"
, <|"Method" -> "POST"
  , "Headers" -> {
      "Content-Type" -> "application/x-www-form-urlencoded"
    }
  , "Body" -> {
      "url" -> "http://sbml.org/validator/api/sample-01.xml"
    , "output" -> "xml"
    , "offcheck" -> "u"
    }
  |>
, CharacterEncoding -> None
]
"<?xml version='1.0' encoding='UTF-8'?>
  <validation-results>
    <not-authenticated/>
  </validation-results>"

As you can see it works but you need to authenticate.

$\endgroup$
3
  • $\begingroup$ Thanks. I've been asking for a key but I'm not getting a reply. Was hoping to use it without key like in the curl example. $\endgroup$ Commented Apr 12, 2018 at 1:52
  • $\begingroup$ @MathProtein but they say you need api key just after the initial curl syntax example. $\endgroup$ Commented Apr 12, 2018 at 5:39
  • $\begingroup$ It works without it as well. $\endgroup$ Commented Apr 13, 2018 at 4:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.