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

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"
^^ ^^ ^^ ^^

Related

windows command prompt curl POST to run Azure DevOps pipeline

I am trying to run an Azure DevOps pipeline from the windows command prompt using curl.
Based on Microsoft documentation ( Runs - Run Pipeline ) I should be able to run a pipeline by posting:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
I am able to GET using the command:
curl -u :<PAT> https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
However, I can't figure out how to do a POST for DevOps using curl to run the pipeline.
I have tried the following:
curl -s -X POST -L https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1 -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic <PAT>"
But this returns the error
HTTP Error 411. The request must be chunked or have a content length
I managed to solve my problem which consisted of numerous steps:
Log the API call from the DevOps website to get the correct format of the json-body ( See this question ).
Format the json-body with extra double quotation signs.
Use the {project}-id instead of the ascii-name since it included a special character which the command prompt misinterpret.
Hence the complete curl command was:
curl -X POST -u :<PAT> "https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1" -H "Content-Type: application/json" -d "{""stagesToSkip"": ""[]"", ""resources"": {""repositories"": {""self"": {""refName"": ""refs/heads/master""}}}}"

Rasa nlu server failure

I started the rasa server by typing this command in cmd:
rasa run --enable-api -m models/(my_model).tar.gz --cors "*" --debug
I put this command in another cmd:
curl -X POST localhost:5005/model/parse -d '{"text":"hello"}'
After that I got this error:
{"version":"1.2.2","status":"failure","message":"An unexpected error occurred. Error: Failed when parsing body as json","reason":"ParsingError","details":{},"help":null,"code":500}
Any help? How can I integrate Rasa with Node.js?
Please try
curl -H "Content-Type: application/json" -X POST -d '{"sender":"y1mLd","message":"hi"}' http://localhost:5005/webhooks/rest/webhook
Output would be
[{"recipient_id":"y1mLd","text":"Welcome, Please let me know how I could be a help today!"}]
Hope this helps!
Simple curl without method type worked for me:
curl localhost:5005/model/parse -d '{"text":"hello"}'
I also faced this error on Windows 10 . Following commands worked for me finally.
curl localhost:5005/model/parse -d "{\"text\":\"hello\"}"
and
curl -H "Content-Type: application/json" -X POST localhost:5005/model/parse -d "{\"text\":\"hello\"}"

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.

Variables in cURL

As you all know tokens can be very long strings and become a hassle to copy and past over and over.
How can I store the token string as a variable and call it when I need it in cURL
example
token: "ABCDefG"
I want to be able to call something like:
curl -L --silent --header "Authorization: GoogleLogin auth=${token}"
Inside a bash script, can't you put the token in a variable, like this:
#!/bin/bash
token="ABCDef"
curl -L --silent --header "Authorization: GoogleLogin auth=$token"
Now in the bash script whenever you need to use the token, you just need to use the variable "$token" (remember to enclose the variable in double quotes).
Or you could set an environment variable:
export token=ABCDef
but it's not an elegant solution
You could store the token in an array
tokens=("ABCDeF" "ASDFGh")
Then when you want to call them, use
curl -L --silent --header "Authorization: GoogleLogin auth=${tokens[0]}"
And if you want to add a token you can
tokens+=("qwerty")

How to handle quotes in a shell script

From this question I am able to get a wget url for the oracle jdk.
I intend to use it in a script vis
wget_opts="-c --no-check-certificate --no-cookies --header --load-cookies="Cookie: oraclelicense=accept-securebackup-cookie""
jdk_download_url="http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"
/usr/bin/wget $wget_opts $jdk_download_url
When I echo the above command it appears ok and is able to correctly download the file.
But on running the command in the script I get the below
--2014-06-04 14:19:43-- http://oraclelicense=accept-securebackup-cookie%22/
Resolving oraclelicense=accept-securebackup-cookie"... failed: Name or service not known.
wget: unable to resolve host address “oraclelicense=accept-securebackup-cookie"”
--2014-06-04 14:20:03-- http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz
Resolving download.oracle.com...
Wget gets the wrong URL.
How do I correct this?
Use an array:
wget_opts=( -c
--no-check-certificate
--no-cookies
--header
--load-cookies="Cookie: oraclelicense=accept-securebackup-cookie"
)
jdk_download_url="http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"
# use the exact quoting below
/usr/bin/wget "${wget_opts[#]}" "$jdk_download_url"
Try this:
wget_opts='-c --no-check-certificate --no-cookies --header --load-cookies="Cookie: oraclelicense=accept-securebackup-cookie"'
jdk_download_url="http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"
/usr/bin/wget $wget_opts $jdk_download_url
Check the difference between single and double quotes in the bash manual.
EDIT: In fact you have some mistakes in your wget command line. Here is the correct line.
OPTS="-c --no-check-certificate --no-cookies --header Cookie:oraclelicense=accept-securebackup-cookie"
URL="http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"
wget $OPTS $URL
The --load-cookies option take a file as argument and not a string. We have to use the --header option with Cookie: oraclelicense=accept-securebackup-cookie. After tests, I have seen that wget does not care about spaces in the header field. So we can use directly Cookie:oraclelicense=accept-securebackup-cookie
If you use the --debug option you will see the correct formatted request :
GET /otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz HTTP/1.1
Range: bytes=5307-
User-Agent: Wget/1.15 (linux-gnu)
Accept: */*
Host: download.oracle.com
Connection: Keep-Alive
Cookie: oraclelicense=accept-securebackup-cookie
You need to escape the double quotes that are within other double quotes:
wget_opts="-c --no-check-certificate --no-cookies --header --load-cookies=\"Cookie: oraclelicense=accept-securebackup-cookie\""
Or enclose the string in single quotes if you don't need variable interpolation:
wget_opts='-c --no-check-certificate --no-cookies --header --load-cookies="Cookie: oraclelicense=accept-securebackup-cookie"'
Also, in your command, you need a $ in front of jdk_download_url:
/usr/bin/wget $wget_opts $jdk_download_url

Resources