Reputation: 371
I'm suddenly seeing a problem with code (java) that was working about a week ago using the Box API. I'm getting a 405 Method Not Allowed while doing a POST to create a folder. I have tried to trouble shoot the problem assuming it may have something to do with recent v2 api going live. However, going back to trying the examples in the docs I am also seeing problems. For example, the docs give the following example ...
curl https://api.box.com/2.0/folders -H "Authorization: Bearer MY_V1_AUTH_TOKEN_HERE" -d '{"name":"API Test Create", "parent": {"id": "ID_OF_PARENT_FOLDER_HERE"}}' -X POST
Which does nothing when I test it. No new folder and no output at all. I have tried with different folder IDs (including zero) and and I have tried generating new V1 auth tokens. Still nothing.
From what I understand, the V1 auth tokens should continue to work for a little longer. Is that not correct? Is anyone else seeing this issue?
Here is the existing java code that suddenly now has started giving a 405. It uses apache fluent lib ...
String response = Request.Post(new
StringBuilder(API_BASE_URL).append("/folders/").append(parent_folder_id).toString())
.addHeader("Authorization", API_REQUEST_HEADER)
.bodyString(new StringBuilder("{\"name\":\"")
.append(name).append("\"}").toString(), ContentType.DEFAULT_TEXT)
.execute()
.handleResponse(myResponseHandler);
where API_BASE_URL="https://www.box.com/api/2.0" and API_REQUEST_HEADER="BoxAuth api_key=MY_APP_API_KEY&auth_token=MY_V1_AUTH_TOKEN"
It would be great if there is a quick, even temporary, solution to this issue. Any clues are appreciated.
Upvotes: 2
Views: 1955
Reputation: 8025
The Create a New Folder
method has changed just a bit; this is indicated in the cURL example you've included. Now you must not include the parent folder ID at the end of the request URL, and you must include the parent folder ID in the request body:
String response = Request.Post(newStringBuilder(API_BASE_URL)
.append("/folders").toString()
.addHeader("Authorization", API_REQUEST_HEADER)
.bodyString(new StringBuilder("{\"name\":\"").append(name)
.append("\", \"parent\": {\"id\": \"").append(parent_folder_id).append("\"}}")
.toString(), ContentType.DEFAULT_TEXT)
.execute().handleResponse(myResponseHandler);
EDIT: While I think the method signature change will address your immediate problem, seanrose is spot on in pointing out that you'll need to transition to OAuth2 for long-term stability.
Upvotes: 0
Reputation: 8685
The Bearer header i.e.
Authorization: Bearer {a bearer token acquired through oauth2}
will only work with bearer tokens retrieved through the OAuth 2 process. This header will not work with auth tokens retrieved through the V1 Auth process. You'll need to use the old header style with V1 auth tokens i.e.
Authorization: BoxAuth api_key={your api key}&auth_token={your v1 auth token}
Upvotes: 1