curlrequesthttp-headershttp-get

How can I replicate a curl -u in a header?


With a curl command I execute:

curl -u appId:secret https://api.example.com

This works I then attempt to do it with headers like so:

{
  "Content-Type": "application/json",
  "Authorization": "`Bearer appId`"
}

401 error I then attempt:

{ "Content-Type": "application/json", "Authorization": "Bearer appId+secret" } 401, any idea how I would do this? ••• The purpose is that I need to do something similar in a no code software which is asking me to set the header. So I won't be using curl.


Solution

  • You're trying to set authentication headers in your curl command using JSON-style headers, but you're running into issues.

    Use the -H option: Instead of trying to pass JSON-style headers, you can use the -H option to set individual headers. For example:

    curl -u appId:secret -H "Content-Type: application/json" -H "Authorization: Bearer appId"
    

    This sets the Content-Type header to application/json and the Authorization header to Bearer appId.