0

I get a "400 Bad Request" and "Did you forget the body variable?" Code:

require "rest-client"
require "json"

# This is the ID that you copied down in the last exercise
your_folder_id = "816582409"

# Add the "body" variable here
body = { "description" => "I made this on Codecademy!"
} 

response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}",
JSON.generate(body),
:authorization => "Bearer" << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1"
)

JSON.parse(response.body)["description"]

3 Answers 3

1

The url of api call shouldn't be https://api.box.com/2.0/folders/816582409 or "https://api.box.com/2.0/folders/#{@your_folder_id}" ?

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

Comments

0

You are missing a space between Bearer and nonsense. You have something like:

response = RestClient.put(
"https://api.box.com/2.0/folders/#{816582409}", 
JSON.generate(body),
:authorization => "Bearer " << "AKGEp7MoDfLAKnMyxTt3nSNtohXW3bt1"
)

Comments

0

"https://api.box.com/2.0/folders/#{816582409}" evaluates to "https://api.box.com/2.0/folders/" due to string interpolation. As ararog suggests, put the variable itself in: #{@your_folder_id} or the plain number, not #{816582409}

Comments

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.