cURL - Invalid character is found in given range 'start' - 'stop' - api

I'm making a restful api call, but I'm getting an error.
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
HTTP/1.1 200 OK
Date: Thu, 22 Aug 2013 17:43:19 GMT
Server: Apache
Content-Length: 208
Allow: GET, HEAD, POST
Vary: Authorization
Content-Type: application/json
Has anyone seen this WARNING error before about an invalid character? How do I fix it?
I was calling:
curl https://my/url/for/api --include -H "Content-Type:application/json" -request POST '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' -u user:pass
More info:
extra response at the end of return
curl: (6) Could not resolve host: POST; nodename nor servname provided, or not known
curl: (3) [globbing] nested braces not supported at pos 33

I had a similar situation - my curl request was essentially working, and returning the information I needed, but with warnings, using the following code:
curl -request http://...
It turned out to be the -request parameter, which I'd incorrectly typed. It either needs to be something like:
curl --request GET http://...
or simply not there at all (because GET is the default):
curl http://...

A corrected command line probably looks something like:
curl https://my/url/for/api \
--include \
-H "Content-Type:application/json" \
-d '{ \"type\": \"code\", \"objects\" : [ \"123456\" ] } ' \
-u user:pass
(I split it to multiple lines for readability.) The changes I did:
1 - --request needs two dashes but since you set POST, it was superfluous and I removed it
2 - use -d (or --data) to specify what to POST. --request only takes a single method string
that you can replace POST with in the HTTP request but I don't think you want that.

cURL gets confused about the square brackets in your command. It interprets them as a range of characters it should process. Either way your question would probably fit better on SuperUser than on Stackoverflow.

Related

curl, API request works in Insomnia, but not in generated code for curl

I have request in Insomnia. When I send it via Insomnia, no problemo. But when I generate source code for curl, it shows me this.
curl --request POST \
--url URL \
--header 'Authorization: bearer XXX' \
--header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
--cookie JSESSIONID=XXX \
--form datasetFile=#FOLDER/producthierarchyl1-1.zip
{"message":"Bad Request","logref":null,"path":null,"_embedded":{"errors":[{"message":"Required argument [Publisher datasetFile] not specified","logref":null,"path":"/datasetFile","_embedded":{},"_links":{}}]},"_links":{"self":{"href":"/data-api/public-api/v4/datasets/ingestion/","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}}}
Insomnia output is like this.
> POST PATH HTTP/2
> Host: URL
> user-agent: insomnia/2022.3.0
> cookie: JSESSIONID=XXX
> authorization: bearer XXX
> content-type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> accept: */*
> content-length: 407
* STATE: DO => DID handle 0x170404b14008; line 2077 (connection #27)
* multi changed, check CONNECT_PEND queue!
* STATE: DID => PERFORMING handle 0x170404b14008; line 2196 (connection #27)
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="datasetFile"; filename="producthierarchyl1-1.zip"
| Content-Type: application/zip
| PK�QU�}�%+producthierarchyl1-1.csvUT բ�b
| --X-INSOMNIA-BOUNDARY--
* We are completely uploaded and fine
* HTTP/2 found, allow multiplexing
Where is the catch?
Thanks.
Remove the --header 'content-type: multipart/form-data; boundary=---011000010111000001101001 option.
It really should not be used like this: curl manages that header and the boundary on its own so changing it should only be done in the rare event you truly want and need to fiddle around with it.
A more minor second thing: --request POST should be dropped from the command line, as it is superfluous and easily cause problems if you add --location later on.
Updated
This flaw is said to have been fixed in a later version of Insomnia
For any folks bumping into this issue again, this answer correctly explains the reason for the problem.
Fortunately this should only be reproducible in versions 2022.3.0 and older versions of Insomnia.
If you use the latest one, 2022.5.1, the generated curl will no longer have this problem, example of a multipart request generated:
curl --request GET \
--url http://mockbin.org/request/anything \
--header 'Content-Type: multipart/form-data' \
--form test=test \
--form test=#/Users/yourUserName/Desktop/somefile.txt

Can't load some ontologies from URL via GraphDB API

I can load the MonDO ontology into GraphDB Free 9 with the /rest/data/import/upload/{repositoryID}/url method with this body:
{
"context": "http://purl.obolibrary.org/obo/mondo.owl",
"data": "https://github.com/monarch-initiative/mondo/releases/download/current/mondo.owl",
"format": "RDF/XML"
}
I can also load this via the Workbench, but not programatically:
http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
I set the format line to "Turtle" and I'm getting 202 responses, but the workbench doesn't show any import. It seems like some of the time I see error messages on the workbench's import page, but I don't understand what corrective action to take.
For example, if I intentionally import ICD9 via the workbench, with the wrong format (RDF/XML), then I see
RDF Parse Error: Content is not allowed in prolog. [line 2, column 1]
curl 'http://localhost:7200/rest/data/import/upload/w2/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}
GraphDB handles api key but you should provide file format in the way up or "format":"text/turtle". Hope this helps.
Thanks to Sava from Ontotext, I was able to construct this minimal curl command that successfully loads the ICD9CM Turtle file from the NCBO BioPortal.
curl -d \
'{"type":"url","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","context":"http://data.bioontology.org/ontologies/ICD9CM/"}' \
-H 'Content-Type: application/json;charset=UTF-8' \
-X POST http://localhost:7200/rest/data/import/upload/disease_diagnosis_dev/url
I left out many of the keys, including the timestamp and all of the parserSettings.
I used the - d ... -X POST curl style instead of the --data-binary style
I don't claim to know all of the consequences of those decisions.
Here's my approach in R
library(httr)
post.endpoint <- "http://localhost:7200//rest/data/import/upload/disease_diagnosis_dev/url"
update.body <- '{
"type":"url",
"format":"text/turtle",
"context": "http://purl.bioontology.org/ontology/ICD9CM/",
"data": "http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=9cf735c3-a44a-404f-8b2f-c49d48b2b8b2"
}'
post.result <- POST(post.endpoint,
body = update.body,
content_type("application/json"))
curl 'http://localhost:7200/rest/data/import/upload/abc/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://www.w3.org/TR/owl-guide/wine.rdf","format":"","data":"http://www.w3.org/TR/owl-guide/wine.rdf","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}'
where,
abc - is the repository id
http://www.w3.org/TR/owl-guide/wine.rdf - is the URL to import
1534939094325 - the current timestamp in seconds since epoch (in bash, equivalent to date +%s)
If you want to perform regular updates I advise you to put each file in its own graph (using the "context":"<file's url>") and then replace it with "replaceGraphs":"<file's url>". The database will create a delta and update only the changed statements.

how to send correct curl command to webserver

So I got the data that is being sent to a specific server. Now I want to do the same using curl from my local machine to play around with specific repsonses from the server and learn more about curl as well.
Here is part of my data
POST /auth HTTP/1.1
platform: android
X-Auth-Token: <censored>
Content-Type: application/json; charset=utf-8
Host: api.blabla.com
Accept-Encoding: gzip
And the data that is being sent:
{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}
Now when I try cURL in my dos shell, I try
curl --insecure -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
The response I get from cURL is this:
{"code":401,"error":"blablaTokenRequired"}
Even though I specified the token. So there are two possible scenarios because the token is correct:
It has something to do with the SSL thing? (I use --insecure because I get an SSL error otherwise)
Something about my command is not correct but I can't figure out what.
Can someone kindly help me out? I am trying everything I can without success
I am not sure if I understand your application specific right, but probably one thing you need to take into account:
man curl says:
-d, --data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when
a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the
server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
-d, --data is the same as --data-ascii. --data-raw is almost the same but does not have a special interpreta‐
tion of the # character. To post data purely binary, you should instead use the --data-binary option. To URL-
encode the value of a form field you may use --data-urlencode.
As I can't see in your example the necessity of sending data as HTML form input, probably your application expects just a "raw" POST body and then you have to try this:
curl --insecure -X POST https://api.blabla.com/auth --data--binary '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}'
PS and for sure this is error is not about using --insecure which just asks curl to neglect ssl verification
you forgot the headers and enabling compressed encoding (gzip), however, i believe you can't force curl to only support gzip encoding using the curl command line alone, you will have to use libcurl, this will make the request say "Accept-Encoding: gzip,deflate" on most systems, using --compressed .. if that's not acceptable to you, rewrite it using libcurl (where you can force it to say only "gzip", if you wish, via CURLOPT_ENCODING )
curl -X POST https://api.blabla.com/auth --data '{"blabla_token": "sdsadsad", "blahblah_id": "23213", "locale": "us"}' --header 'platform: android' --header 'X-Auth-Token: <censored>' --header 'Content-Type: application/json; charset=utf-8' --header 'Host: api.blabla.com' --compressed
another gotcha: on some systems, there will be a default useragent header (like debian 6), while on some systems, curl comes without a default useragent (like debian 8).. you might want to use --user-agent '' too

unable to create schema in MarkLogic database

I used the following syntax from documentation
curl -X POST --anyauth --user admin:admin \
--header "Content-Type:application/json" \
-d '{"view-schema-name": "mySchema"}' \
http://localhost:8002/manage/v2/databases/SQLdata/view-schemas?format=json
your thoughts please! TIA
Error msg -
curl: (3) [globbing] unmatched close brace/bracket in column 9
{"errorResponse":{"statusCode":"415", "status":"Unsupported Media Type", "messag
eCode":"REST-INVALIDMIMETYPE", "message":"REST-INVALIDMIMETYPE: (rest:INVALIDMIM
ETYPE) Content-Type must be one of: 'application/json', 'application/xml', Rece
ived: application/x-www-form-urlencoded"}}
As I mentioned before, the output of your cUrl command will be helpful. But without that, the only error I can imagine from your sample is of the database SQLdata does not exist..

How to post JSON data using curl over basic http auth?

I want to post data using curl unix command what I got by googling is doing like below:
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"description": "This will prbbly be my lst post.", "transaction_id": "2011-05-22T00:46:38", "account": "another-post"}' http://127.0.0.1:8000/api/transaction/
But its is returning following response header like below:
curl: (6) Could not resolve host: POST; nodename nor servname provided, or not known
HTTP/1.0 401 UNAUTHORIZED
Date: Sat, 09 Jun 2012 18:50:37 GMT
Server: WSGIServer/0.1 Python/2.7.1
Content-Type: text/html; charset=utf-8
What I am doing wrong
You don't need to write "POST" to make curl(1) post - it will do that automatically if you give it a --data argument.
Instead, it is mistaking "POST" for the URL you want to send to, and failing as you might imagine. Drop that word and you should be good.