Issues with using curl in shell script - shell

When I try to use curl command in my shell script I get the following error message: curl: (1) Protocol "http not supported or disabled in libcurl
When I use the curl command with the same http:// argument on my terminal, I get a response from the site. Am I missing something?
Thanks
Update
var4="localhost:8983/xxx?yyy";
var5="-F stream.url=nexus.cvs.ula.abc.html";
var6='"'$var4'" '$var5
curl $var6

The error message
curl: (1) Protocol "http not supported or disabled in libcurl
makes me think that the URL you're passing may be
"http://someserver/somelink"
instead of
http://someserver/somelink
and curl is thinking that " is part of the url.
EDIT:
Based on your update, I'd say it should be:
var4="http://localhost:8983/xxx?yyy";
var5="-F stream.url=nexus.cvs.ula.abc.html";
curl $var5 $var4

Related

How do I format a variable inside the broken double quotes of a curl command?

I am trying to test the Sumo Logic API by updating the information of my collector. The second curl command is the one that is causing the issue 'curl: (55) Failed sending PUT request'. It works in my terminal but not in the bash script.
#!/bin/bash
readonly etag=$(curl -u '<accessId>:<accessKey>' -I -X GET https://api.sumologic.com/api/v1/collectors/<id> | grep -Fi etag | awk '{print $2}' | tr -d \''"\')
echo ${etag}
curl -vvv -u '<accessId>:<accessKey>' -X PUT -H "Content-Type: application/json" -H "If-Match: \"${etag}\"" -T updated_collector.json https://api.sumologic.com/api/v1/collectors/<id>
set -x
The first curl command is assigned to the variable called 'etag' which stores the necessary etag. The etag is used in the second curl command to make a request to update the information stored in the 'updated_collector.json'. The updated_collector.json file is not the issue as I have successfully updated the information via the terminal with it. I suspect the content-type is not being sent in the header because someone ran the script on their end and it was not showing that information with the -vvv tag.
Here you can find the Sumo Logic Collector API Methods and Examples from which I got the curl commands to test the API: https://help.sumologic.com/APIs/Collector-Management-API/Collector-API-Methods-and-Examples
Update: I retieved the etag and then ran the second command in a bash script. I manually inserted the etag into the ${etag} portion of the second curl command. I then ran the script and it worked. Therefore, the etag variable isn't correctly formatted inside the second curl command. I do not know how to fix this.
The issue was partially the syntax but after fixing that, I was still getting an error. "If-Match: \"${etag}\" in my command should be "If-Match: ${etag}" instead. I had to add the --http1.1 flag for it to work. I'm sure this is a sumo logic issue. I am able to execute GET requests no problem using http2.0.

Jira API GET all users from Jira project with specific status

In my Ruby app I'm trying to get all agent users from my service desk board. It means all users with status: 'ServiceDesk'. Is it possible using only base auth?
In curl I was trying something like:
curl -D -u USERNAME:PASSWORD -X GET -H "Content-Type: application/json" https://company_name.atlassian.net/rest/api/2/user/assignable/search?project=SERVICEDESK
But all what I get is an error:
Warning: The file name argument '-u' looks like a flag.
curl: (3) URL using bad/illegal format or missing URL
{"errorMessages":["Internal server error"],"errors":{}}%
Is there any way to get those data with basic auth?
I think there's an issue with the curl command, try this
curl -D- -u USERNAME:PASSWORD https://company_name.atlassian.net/rest/api/2/user/assignable/search?project=SERVICEDESK

Twilio-call bash script returns 404 NOT FOUND

I have a paid twilio account with verified number and am trying to use the bash script supplied by twilio entitled "twilio-call" on Ubuntu 16.04.3 LTS. The response is: Failed to call 941-8XX-XXXX: curl (22): The requested URL returned: 404 NOT FOUND.
I know that I have the credentials set correctly as the bash script entitled "twilio-sms" works flawlessly.
The bash script "twilio-call" has been downloaded directly from twilio.com/labs/bash and the permissions have been set correctly.
The actual curl command is:
RESPONSE=curl -fSs -u "$ACCOUNTSID:$AUTHTOKEN" -d "Caller=$CALLERID" -d "Called=$PHONE" -d "Url=http://twimlets.com/message?Message=$MSG" "https://api.twilio.com/2008-08-01/Accounts/$ACCOUNTSID/Calls" 2>&1
The variables $ACCOUNTSID, $AUTHTOKEN, $CALLERID, $PHONE, and $MSG have all been verified to be populated correctly.
What could be causing this 404 response? Am I correct in my understanding that a verified number from twilio which works correctly for sms should also work for call?
It must be some old example at Twilio. Where did you find it?
The API endpoint URL it's not
https://api.twilio.com/2008-08-01/Accounts/$ACCOUNTSID/Calls
it is
https://api.twilio.com/2010-04-01/Accounts/$ACCOUNTSID/Calls

Different body for same Curl request sent from Windows and Ubuntu

I'm trying to send a curl request from both Windows and Ubuntu system to a Rest API. following is the request
curl -k -X POST http://172.16.76.1:8080/test -d 'sample_param={"user_info":{"name":"abc","age":"20"}}'
When I read this from the server side, I get the following two different content data from each OS
Body for curl request from Ubuntu:
sample_param={"user_info":{"name":"abc","age":"20"}}
Body for curl request from Windows:
sample_param={user_info:{name:abc,age:20}}
(Note that double quotations are missing)
As a result I cannot get the json object from the request.
Can someone point out the mistake and give a solution for this.
Thanks in advance
Changing the curl command to following worked
curl -k -X POST http://172.16.76.1:8080/test -d "sample_param={\"user_info\":{\"name\":\"abc\",\"age\":\"20\"}}"

How to post PUT request under the Windows using curl?

I need to post XML data via curl.exe under windows using PUT request.
In the curl help I found:
-d/--data <data> HTTP POST data (H)
What should I supply for <data>?
curl sample calls
# with inlining plain data
curl -X PUT -d "payload" http://localhost
# referrring file
curl -X PUT -d #myXmlFile.xml http://localhost
If your windows curl-port does not support it go for cygwin. It is a linux-like environment for windows and also offers "a proper" curl.
In windows, if a double-quoted argument itself contains a double quote character, the double quote must be doubled.
For example, enter 'This is "quoted" payload' as "This is ""quoted"" payload" which is very different than in Unix.
Example:
curl -X PUT -d "This is ""quoted"" payload" http://localhost
in windows you'll need to put the # inside the quotes for the file you're sending:
curl -XPUT --data-binary "#uploadme.txt"
otherwise you'll get weird errors as it tries to use the content of the file as the url:
curl: (6) Couldn't resolve host 'upload'
curl: (6) Couldn't resolve host 'me!'
(uploadme.txt contains "upload me!")
on Windows CMD, curl refers to C:\Windows\System32\curl.exe so you can use
curl -X PUT -d "payload" http://localhost
instead on Windows PowerShell curl refers to Invoke-WebRequest so it is not working with curl syntax. you can use curl.exe on PowerShell to call C:\Windows\System32\curl.exe so it will solve the issue.
curl.exe -X PUT -d "payload" http://localhost

Resources