0

I need to consume the linode api, in the description it says I have to send the data using curl like this

curl -H "Content-Type: application/json" \
    -H "Authorization: Bearer $TOKEN" \
    -X POST -d '{
        "label": "asdfasdf"
        "ssh_key": "asdfasdf"
    }' \
    https://api.linode.com/v4/profile/sshkeys

I tried using


http = Faraday::Connection.new 'https://api.linode.com/v4/profile/sshkeys'
http.authorization :Bearer, token
http.post('', { 'label' => 'adfadf', ..}.to_json)

But every request it says label and ssh_key required. I don“t know how to send this particular request

anyone?

Fernando
  • 61
  • 5

1 Answers1

1

You need to specify the content-type as json in the header, if you're sending a json data.

http.post(
  '',
  { 'label' => 'adfadf', ..}.to_json,
  { 'Content-Type' => 'application/json' }
)

Reference: https://lostisland.github.io/faraday/usage/

Rein Avila
  • 375
  • 1
  • 6