2

In below example (which I got it from PagerDuty webpage):

machine="hi" curl -H "Content-type: application/json" -X POST \
-d "{ \"service_key\": \"e93facc04764012d7bfb002500d5d1a6\", \"description\": \"FAILURE for production/HTTP on machine $machine\" }" \
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"

I want to use variables in description like:

  "description": "FAILURE for $machine",

However it does not work and it only shows me the "FAILURE for $machine", I tried "FAILURE for ${machine}", but it does not work too. Do you know how to solve it?

1
  • This question makes no sense. You should not edit the question to eliminate the need for an answer. Please revert to version 2; the edit in version 3 is completely wrong. Commented Sep 27, 2014 at 16:34

1 Answer 1

2

The problem is that use use single quotes. You need to use double quotes and escape and double quote in the string:

curl -H "Content-type: application/json" -X POST \
-d "{    
  \"service_key\": \"e93facc04764012d7bfb002500d5d1a6\",
  ...
  \"description\": \"FAILURE for production/HTTP on machine $machine\"
}" \
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"

Quite tedious, but it will do the job.

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

20 Comments

Thanks Why doing this for service key?
Just to show an example. You need to escape ANY " in the text if using double quotes for the string.
It doesnot work it shows me {"status":"unrecognized object","message":"Event object format is unrecognized","errors":["JSON parse error"]}T
Sorry, forgot to escape one of the quotes.
Oh That was my problem editing in notepad++. Thanks a lot for your help
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.