16

I have been asked to call a restful api via Unix environment. Is there a bug in my command so i got blow issue?

I have tried looking at the curl --help but the thing that I could find that might help would be the way to pass in param key-pair. Could it be possible to give me an example how to debug such api calling?

$ curl -d param1=xxx&param2=yyy -X POST https://restful_api_path/lifecycle/v1/resource_node
[1]     10276
[2]     10277
-ksh: -X: not found [No such file or directory]
[2] +  Done                    curl -d param1=xxx&param2=yyy -X POST https://restful_api_path/lifecycle/v1/resource_node
$ curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

Cheers

2
  • Enclose your params in quotes - curl -d 'param1=xxx&param2=yyy' Commented Jul 25, 2016 at 9:07
  • Didn’t you ever wonder what the lines [1] 10276 and [2] 10277 might signify? Commented Jul 25, 2016 at 9:18

3 Answers 3

15

You need to enclose your params in single or double quotes. e.g.

curl -d 'param1=xxx&param2=yyy' -X POST https://restful_api_path/lifecycle/v1/resource_node

This is because the & operator in BASH is used to signify that the command should continue to run the in background, hence it must be quoted or escaped if you want a literal ampersand.

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

Comments

7

I think you need to add double quotes to quote arguments:

curl -d "param1=xxx&param2=yyy" -X POST https://restfulurl/lifecycle/v1/resourcenode

P.S. On Windows you need to use double quotes, not single quotes. But in Unix, it supports both double and single quotes to quote arguments. So below cmd are fine also:

curl -d 'param1=xxx&param2=yyy' -X POST https://restfulurl/lifecycle/v1/resourcenode

Comments

-3

envsubst < $WORKDIR/migrate-storage/incident.json | curl -X POST -H "Content-Type: application/json" $FUNCTION_URL -d @-

1 Comment

This does not answer the question being asked.

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.