-1

I have an authentication problem with a REST API Call with curl, I think its to do with the formatting of my curl input.

curl -v https://api.ananthsdomain.com/version1/testaccount/test \
     -H "Accept: text/xml \
         User-Agent: MyIn Interface \
         X-Api-Signature:  XXXXXXX+u:`date +%Y%m%d%H%M%S`:`echo XXXXXXX$(date +%Y%m%d%H%M%S)XXXXXXX | openssl dgst -binary -sha1 | openssl base64`"

I have to construct X-Api-Signature to match requirements from servers which includes API key, current date and sha1hash of the API key.

I'm receiving authentication error and I think it's because the signature is being set in the same line as User-Agent (output below)

Accept: text/xml
User-Agent: MyIn Interface           X-Api-Signature:  XXXXXXX+u:20160210112839:O9bXXXXXXXXXXXlVAXXXXXXXXXX=

The output I want to see is meant to be like this.

Accept: text/xml
User-Agent: MyIn Interface
X-Api-Signature: XXXXXXX+u:20160210112839:O9bXXXXXXXXXXXlVAXXXXXXXXXX=

How can I make curl produce the output so it appears like the above.

GregL
  • 9,370
  • 2
  • 25
  • 36
akarc
  • 11
  • 3

2 Answers2

2

Just to expand on @mschuett's answer, you should specify each header with it's own -H option, and curl will append the proper end-of-line marker.

Thus, your command would look like:

curl -v https://api.ananthsdomain.com/version1/testaccount/test  \
  -H "Accept: text/xml" \
  -H "User-Agent: MyIn Interface" \
  -H "X-Api-Signature:  XXXXXXX+u:`date +%Y%m%d%H%M%S`:`echo XXXXXXX$(date +%Y%m%d%H%M%S)XXXXXXX | openssl dgst -binary -sha1 | openssl base64`"
GregL
  • 9,370
  • 2
  • 25
  • 36
1

Take a look at the fine manual, which says for the -H/--header option: This option can be used multiple times to add/replace/remove multiple headers.

mschuett
  • 3,146
  • 21
  • 21