CURL command not executing in SSH - json

I am trying to execute a CURL command to set a greeting message for a bot I am building. Guidance from Facebook here: https://developers.facebook.com/docs/messenger-platform/thread-settings/greeting-text
Example from Facebook:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"greeting",
"greeting":{
"text":"Timeless apparel for the masses."
}
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
I am trying to run that from a SSH command prompt -- the only change I made was make it into 1 line, so that I can execute it from command line in one go.
curl -X POST -H "Content-Type: application/json" -d '{"setting_type":"greeting", "greeting":{"text":"Hi {{user_first_name}}! I am a bot. Simply say 'Hi' to start.. yes, it's as simple as that!"}}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=EAAFXmrm6M8cBAHF2TwfWMnQfksHnZBtQQIHYWjIFpmTffkG"
But, I get this error message from SSH when trying to execute above 1 liner.
-bash: !"}}': event not found
What am I doing wrong here? Any help is appreciated.

You have a problem with single quotes ', you can replace them with \u0027 :
curl -X POST -H "Content-Type: application/json" -d '{"setting_type":"greeting", "greeting":{"text":"Hi {{user_first_name}}! I am a bot. Simply say \u0027Hi\u0027 to start.. yes, it\u0027s as simple as that!"}}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=EAAFXmrm6M8cBAHF2TwfWMnQfksHnZBtQQIHYWjIFpmTffkG"

Related

base64 conversion in context with curl

I would like to send a message and attachment via signal-cli.
I successfully set up docker a container by bbernhard/signal-cli-rest-api.
Normal message sending with curl-statement works fine and statement looks like:
curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"number\": \"+490000000\", \"recipients\": [\"+4900000000"]}' 'http://localhost:48080/v2/send'
The message will be sent to one recipient or many. Also working for a group by groupID.
Question: How to add an attachment like a JPG?
If I add \"base64_attachments\": [\"${ENCODED_IMAGE}")\"] to the statement, then i get the error message {"error":"Couldn't process request - invalid request"}
Full bash script looks like :
#!/bin/bash
INPUT_FILE="/path/to/file/IMG_5098.JPG"
TMPFILE=$(mktemp)
base64 "${INPUT_FILE}" --wrap=0 > "${TMPFILE}"
ENCODED_IMAGE=$(cat "${TMPFILE}")
curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"base64_attachments\": [\"${ENCODED_IMAGE}")\"], \"number\": \"+4900000\", \"recipients\": [\"+4900000000\"]}' 'http://localhost:48080/v2/send'
rm "${TMPFILE}"
I expected the image send as well as the message

How create Issues with API/CURL to Bitbucket

I'm trying to create issues in Bitbucket with the Windows CURL command, but it doesn't work, I'm getting this error message:
{"type": "error", "error": {"message": "No import job started"}}
My command CURL:
curl -u username:password -X GET https://api.bitbucket.org/2.0/repositories/name/name2/issues/import -H "Content-Type: application/json" --data #data.jsonson
I'm trying to send the following result in JSON:
{
"title": "title"
}
But it doesn't work.
Does anyone know how I can create issues?
I suppose, you should use a different URL path for posting issues, please see here for post method. It should be like this: https://api.bitbucket.org/2.0/repositories/username/reponame/issues
For posting just an issue with a title you could use this:
curl --ssl-no-revoke -u username#password -X POST -H "Content-Type: application/json" -d "{\"title\" : \"test2\"}" https://api.bitbucket.org/2.0/repositories/username/reponame/issues
To post a content of the issue use content tag:
curl --ssl-no-revoke -u username#password -X POST -H "Content-Type: application/json" -d "{\"title\" : \"test2\",\"content\": {\"raw\": \"just test text\", \"markup\": \"plaintext\"}}" https://api.bitbucket.org/2.0/repositories/username/reponame/issues
For example for me this worked (it's my private repo):
curl --ssl-no-revoke -u myaccountname#mypasswordname -X POST -H "Content-Type: application/json" -d "{\"title\" : \"test2\",\"content\": {\"raw\": \"just test texts\", \"markup\": \"plaintext\"}}" https://api.bitbucket.org/2.0/repositories/dvmochalov/testrepo/issues
--ssl-no-revoke - works only for windows curl and it's just in case if you are running Windows with antivirus software or working with proxy.

How to GET data of a key in json using curl?

Sorry Pretty noob to json.
Basically I have a simple server where I can upload data in there.
E.g:
curl -vX PUT "http://IP:port/ABC" -H "Content-Type: application/json" -d #"Once Upon a time."
After when I do:
curl -vX GET "http://IP:port/ABC" -H "Content-Type: application/json"
I get:
{"reverse_shell":
{"aliases":{},"mappings":{},"settings":
{"index":{"creation_date":"1561863982371","number_of_shards":"5","number_of_replicas":"1","uuid":"IAWE83rYQqmtKW-9svkBVg","version":{"created":"6040299"},"provided_name":"ABC"}
}
}
}
As you can see there is no where mentioning Once Upon a time, so is there I am missing? or how do I get that data from json using curl?
I am in kali linux env.
It looks like you are trying to post a string as a file.
When you specify a "#" with -d this tells curl to send the data from a file called "Once Upon a time."
If you are trying to put a file then you should do:
my_text_file.txt
Once Upon a time.
curl -vX PUT "http://IP:port/ABC" -H "Content-Type: application/json" -d #./my_text_file.txt https://server/api/path

Error in Facebook Webhook

I'm following the steps given by Facebook's webhook setup found here: https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup. No more, no less.
And I'm having a hard time in this step:
When I enter the following line curl -H "Content-Type: application/json" -X POST "localhost:1337/webhook" -d '{"object": "page", "entry": [{"messaging": [{"message": "TEST_MESSAGE"}]}]}' in the command line, I get this error:
What could the issue be?
Just delete the ' from the command like this:
curl -H "Content-Type: application/json" -X POST "localhost:1337/webhook" -d '{"object": "page", "entry": [{"messaging": [{"message": "TEST_MESSAGE"}]}]}

How to execute the same curl request on a sequence of server IPs (URLs)

Command
curl -v -H "Accept: application/json" -H "Content-type: application/json" \
-X POST -d '{"test": "some data"}' http://XX.XX.X.001:8080/services/test
I want to execute the above same curl command on different servers (IP addresses). Is there any way or CURL command so I can execute this service on all servers, instead of changing the IP address every time manually?
I have servers IP in some sequence, e.g.
http://XX.XX.X.002:8080/services/test
http://XX.XX.X.003:8080/services/test
...
You can either use shell's brace expansion in bash, e.g. {2..15} for 2,3,4,...,15:
curl ... http://x.x.x.{2..15}:8080/services/test
or, curl's alphanumeric series [] operator in the URL part (notice the double-quotes):
curl ... "http://x.x.x.[2-15]:8080/services/test"
Alternatively, you can use arithmetic for loop:
for ((i=2; i<=15; i++)); do
curl ... "http://x.x.x.$i:8080/services/test"
done
You could use a loop:
for HOST in 0.0.0.1:8080 0.0.0.2:8080; do curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"my": "data"}' http://$HOST/services/test ; done
If your hosts are sequential then randomir's answer is a lot cleaner.