8

I'm writing batch script which should send request with json.

call curl -X POST -H 'Content-type: application/json' --data '{"text": "Pull requests:\n%linksText% has been deployed to %stagingServerUrl%", "username": "Staging Server"}' http://requestb.in/ovehwtov

I run my script from git bash and alhought it sends the request, the body is malformed and just before it sends the request I see errors in console:

curl: (6) Couldn't resolve host 'application'
curl: (6) Couldn't resolve host '"Pull'
curl: (6) Couldn't resolve host 'requests:\nhttp'
curl: (6) Couldn't resolve host 'has'
curl: (6) Couldn't resolve host 'been'
curl: (6) Couldn't resolve host 'deployed'
curl: (6) Couldn't resolve host 'to'
curl: (6) Couldn't resolve host 'unicorns2url",'
curl: (6) Couldn't resolve host '"username"'
curl: (6) Couldn't resolve host 'Staging'
curl: (3) [globbing] unmatched close brace/bracket in column 8
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    11    0     2  100     9      6     30 --:--:-- --:--:-- --:--:--    30ok

Here's how body looks:

'{"text":

which isn't right.

As you can see I'm composing the json from variables, but it's not the cause of failure: when I remove them and call

call curl -X POST -H 'Content-type: application/json' --data '{"text": "Pull requests has been deployed to", "username": "Staging Server"}' http://requestb.in/ovehwtov

The same error happens.

However when I copy this command from my batch script and paste it directly into git bash console It works seamlessly. Don't ask me why I'm running windows batch script from git bash, when I could write bash script using bash language instead of awkward and confusing DOS syntax. I didn't realize that when I started writting the script and it's almost done (except for this part). How to make it work? Thanks!

2
  • 1
    In cmd-interpreted commands, tokens containing spaces need to be enclosed in double quotes. Try call curl -X POST -H "Content-type: application/json" --data "{'text': 'Pull requests:\n%linksText% has been deployed to %stagingServerUrl%', 'username': 'Staging Server'}" http://requestb.in/ovehwtov. Commented Mar 14, 2017 at 23:03
  • Thank you, good sir. Although single quotes are not allowed in json, so it should be call curl -X POST -H "Content-type: application/json" --data "{\"text\": \"Pull requests:\n%linksText% has been deployed to %stagingServerUrl%\", \"username\": \"Staging Server\"}" http://requestb.in/qkebavqk Commented Mar 15, 2017 at 8:50

1 Answer 1

14

Try:

curl -X POST -H "Content-type: application/json" --data "{\"text\": \"Pull requests has been deployed to\", \"username\": \"Staging Server\"}" http://requestb.in/ovehwtov

Obviously with the right data.

If you're on Windows you have to use "\".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.