I have a problem sending the access token request with box api and the rest client gem :
request
access_token_params = {
grant_type: 'authorization_code',
code: params[:code],
client_id: box_params[:client_id],
client_secret: box_params[:client_secret]
}
RestClient.post('https://app.box.com/api/oauth2/token', params: access_token_params){ |response, request, result, &block|
check_request_success(response, "send_access_token")
}
with:
def box_params
{
client_id: "my_id",
client_secret: "my_secret"
}
end
error:
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
First
Your
RestClient.post()
function incorrect. Because it is apost
you should not haveparams:
hash but rather the payload itself. This is because post requests don't have params in the url, but rather in a payload in the body of the request.Second
The Box API Docs & Oauth Tutorial page reference two endpoints. The correct endpoint for the request on the API docs:
https://api.box.com/oauth2/token
Try this: