Parivalavan
Parivalavan

Reputation: 11

Box API Create folder

I'm a developer and new to box.

I'm trying to create folders using Box API 2.0. I have created an application and got the api key. I have successfully obtained the authorization token for my login "[email protected]".

Using these credentials when I try to create a folder using the following:
url: "https://www.box.com/api/2.0/folders/321654595?response_type=xml"
xml: "<?xml version='1.0' encoding='UTF-8' ?><request><api_key>API_KEY</api_key><auth_token>AUTH_TOKEN</auth_token><name>New Folder</name></request>"

I get the following response

<?xml version="1.0" encoding="UTF-8"?>
<error><status>401</status><code>unauthorized</code><help-url>http://developers.box.com/docs/#errors</help-url><message>Unauthorized</message><request-id>1341258286500ca4843dfa7</request-id></error>

I use perl and "LWP::UserAgent & HTTP::Request::Common" modules for http calls.

Am I going down the correct path or missing something that is obvious.

Thanks,
Pari
[email protected]

Upvotes: 1

Views: 2498

Answers (2)

Ben Zittlau
Ben Zittlau

Reputation: 2485

I'm not particularly familiar with using XML with Box's API, but I'm not sure that you can provide the authentication information in the body of the request. You should try putting the authentication information into a header like shown in their docs here.

Basically try putting the auth information in an Authorization HTTP header of the following format:

Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN

Upvotes: 0

seanrose
seanrose

Reputation: 8685

A well-formatted request to create a folder should look like:

POST https://api.box.com/2.0/folders/{parent folder id}.xml

with a body of

<folder>
<name>
{the folder name}
</name>
</folder>

Note the following things:

  1. The base URL is https://api.box.com/2.0, not www.box.com and not over http
  2. .xml is appended to the end of the request to signify that xml is being sent and expected to be returned
  3. There is an enclosing <folder> tag around the data which is different from the way the JSON is sent.

Upvotes: 1

Related Questions