Navarro Navarro - 1 year ago 132
reST (reStructuredText) Question

Making a POST request with Chef

I need to post a .json file to a server with a rest API with a Chef recipe, following Chef's documentation I came up with this code:

http_request '/tmp/bpp.json' do
url 'http://localhost:8080/api/v1/blueprints/bpp'
headers ({
'AUTHORIZATION' => "Basic #{Base64.encode64(user)}",
'CONTENT-TYPE' => 'aplication/json'
action :post

For authorization token,
is a variable that contains

When I run this chef recipe I obtain the following response:

Error executing action `post` on resource 'http_request[POST /tmp/bpp.json]'

400 "Bad Request"

Prior to this I was just executing a
call and it was working fine, but I need to change to the
resource. This was the old (working)

curl --user user:password -H 'X-Requested-By:My-cookbook' --data @/tmp/bpp.json localhost:8080/api/v1/blueprints/bpp

I am not very used with REST apis and seems like an uncharted territory to me.

Answer Source

You forget about message. Using file name as resource name won't send this file as data. Try adding:

message your_json

In your case only the resource name - /tmp/bpp.json, will be sent. Not a file content. As stated in linked doc:

The message that is sent by the HTTP request. Default value: the name of the resource block See “Syntax” section above for more information.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download