Windows Variant of the following Linux code - linux

The Following code is working on Linux but with windows bat file it throws an error :
curl -X PUT --anyauth -u admin:admin --header "Content-Type:application/json" -d {"range-element-index":[{"scalar-type":"string", "namespace-uri":"", "localname":"userName", "collation":"http://marklogic.com/collation/codepoint", "range-value-positions":true,"invalid-values":"reject"}]} http://localhost:8002/manage/v2/databases/db/properties
and the error is as follows :
curl: (6) Could not resolve host: namespace-uri
curl: (6) Could not resolve host: localname
curl: (6) Could not resolve host: collation:http
curl: (3) [globbing] unmatched close brace/bracket in column 49
{"errorResponse":{"statusCode":"400", "status":"Bad Request", "messageCode":"XDMP-JSONCHAR", "message":"XDMP-JSONCHAR: xdmp:unquote(\"{range-element-index:[{scalar-type:string,\", (), \"format-json\") -- Unexpected character 's' in JSON at line 1 char 36"}}

Indeed, the issue is likely the fact that the rest payload needs to be quoted.
There are various places in the ML guides that show windows versions of commands (such as for MLCP).
As an example of your challenge - and what looks like the solution, please see the conversation at the bottom of this page - including screen-shots of a cUrl command on windows:
https://developer.marklogic.com/learn/rest/setup

Related

Getting this error: curl: (3) Host name ' --url' contains bad letter

I am trying to run this line on a linux machine:
curl --request GET \ --url 'https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb' \ --output 'nessus.deb'
but I am getting this error:
curl: (3) Host name ' --url' contains bad letter
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: " to save to a file.
I ended up using: wget https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb
but it seems I should not have done it this way because now the subsequent line I want to run isn't working: dpkg -i nessus.deb
The output for the curl was 'nessus.deb'. So to install you had to use 'dpkg -i nessus.deb'.
However, because you used wget, it did not create the output name, but just saved 'INSERTFILENAMEHERE'. So to install it, you would use:
'dpkg -i *INSERTFILENAMEHERE*'
For example, you would have put in
'wget https://www.tenable.com/downloads/api/v2/pages/nessus/files/Nessus-10.4.2-ubuntu1404_amd64.deb'
Then it would say something like
''Nessus.deb' saved'
So you would then put in.
'dpkg -i Nessus.deb'
And it would install the package. In short, the reason why the line was not working was because the file was there, but the name did not match.

Run query API in curl

I'm trying to explore the curl connect or retrieve the data with query API link but when I run my GET command in curl it runs without any error shown in -vv but the process stop. below the actual statement at the end of the posted process, may I know if this is normal or I need to add an additional arguments or parameters on my command for me to retrieve the data? If yes may I know how to do it?
Connection #1 to host myserver.com left intact
My command
curl -vv -k -X GET -H --user user123:password1 -H "Accept: application/json" https://myapplink/statement/EXE=sample

curl command - could not resolve xn--x-5gn/post on Ubuntu

I am using curl command to call rest api. I want to post data and my curl command looks like:
curl –x POST -u 'username:PW' -k -H "Content-Type:application/json" -d '{"json-input":{"handler":"getContent","image":true,"video":false,"text":false,"source":"1","lage":"testlage1"}}' -i http://localhost:8080/com.knime.enterprise.server/rest/v4/jobs/3fd2ca61-c173-4160-a20d-45c387f65f64
I am getting following message:
curl: (6) Could not resolve host: xn--x-5gn curl: (6) Could not
resolve host: POST
The letter before X is wrong. It is supposed to be an ascii minus ('-', ascii code 0x2d / 45) and not the unicode dash character (U+2013) as used in the question.
curl will treat all options that don't start with a minus as a URL, which makes it convert the dash-X string to a IDN hostname and try it. It then continues to try the "POST" host name as that follows the dash-X... None of those host names can be resolved, which is the curl error messages you see.
Then finally: don't use -X POST when you do a post with -d (or with -F)! Just remove the -X POST entirely and things will work better.
check the codepage settings of the terminal software in use and compare these to the host settings
in our case we saw the same strange hostname error returned to a simple
curl -v http://{hostname}:{port}
we discovered the problem was the dash character; the codepage specified in Putty was not consistent with the codepage used at the host so curl treated the -v expression as the hostname.

SUSE Linux terminal is not recognizing some characters like "&", "?", "/"

when i run this in terminal
curl https://api.box.com/2.0/folders/{id}/items?limit=100&offset=0 -H "Authorization: Bearer access_token"
with valid access_token it gives me this response.
If '-H' is not a typo you can run the following command to lookup the package that contains the binary:
command-not-found -H
-bash: -H: command not found
I am using SUSE Linux Enterprise Server 11 SP3.
All these characters you mention have to be escaped to prevent them from being interpreted by bash.
So for example instead of:
curl https://www.example.com/r?v=1&w=2
You need to use:
curl https://www.example.com/r\?v=1\&w=2
^^ ^^
In your case:
curl https://api.box.com/2.0/folders/\{id\}/items\?limit=100\&offset=0 -H "Authorization: Bearer access_token"
^^ ^^ ^^ ^^

Unable to call system('curl') from MATLAB 2013 a

Here is the experiment I tried on Ubunu 14.04.
curl -X POST -d '<request>something<\request>' --header "Content-Type:application/xml" url
This command works on the terminal but it does not work as a MATLAB command using system(cmd) i.e.
cmd = 'curl -d ''<request>something<\request>'' url' ;
system(cmd)
here is the error message from MATLAB:
curl: /usr/local/MATLAB/R2013a/bin/glnxa64/libcurl.so.4:
no version information available (required by curl)
curl: (48) An unknown option was passed in to libcurl
:1: parser error : Document is empty
^-:1: parser error : Start tag expected, '<' not found ^
ans = 1
I do not have any libcurl.so files except under /usr/local/MATLAB/R2013a/bin/glnxa64/.
sroot#ubuntu14:~$ ls /usr/lib/libcu*
ls: cannot access /usr/lib/libcu*: No such file or directory
sroot#ubuntu14:~$ ls /usr/local/lib/libcu*
ls: cannot access /usr/local/lib/libcu*: No such file or directory
Regards,
On my Ubuntu, the libcurl*.so.* are here
> $ ls /usr/lib/x86_64-linux-gnu/libcurl*
> /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.3
> /usr/lib/x86_64-linux-gnu/libcurl-nss.so.4.2.0
> /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4
> /usr/lib/x86_64-linux-gnu/libcurl.so.3
> /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.2.0
> /usr/lib/x86_64-linux-gnu/libcurl.so.4
> /usr/lib/x86_64-linux-gnu/libcurl-nss.so.3
> /usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
> /usr/lib/x86_64-linux-gnu/libcurl-nss.so.4
And as for problem in calling curl from within matlab, you can redirect '/usr/local/MATLAB/R2013a/bin/glnxa64/libcurl.so.4' to '/usr/lib/x86_64-linux-gnu/libcurl.so.4'.

Resources