Вопрос

I have been using box-api v1.0 and now see there is a new one and would like to take advantage of it. However I am very new to REST and don't really understand what to do here.

My code for getting folders was this:

wcGetFolders.OpenReadAsync(new Uri("https://www.box.net/api/1.0/rest?action=get_account_tree&api_key=" + api_key + "&auth_token=" + auth_token + "&folder_id=" + currentFolder + "&params[]=onelevel&params[]=nozip"));

But now with the new API I am unsure on how to format the string.

Previously I was able to put all the parameters inside the uri.

Can I still do that?

The new API help indicates that the request looks like this:

https://api.box.com/2.0/folders/FOLDER_ID \
-H "Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN" \

I don't know what to do with the backslashes and the quotes, basically I don't know at all how to format the uri and even if all the -h etc parameters actually go into it at all.

Это было полезно?

Решение

The example requests in the documentation are given for cURL, a command line tool for making HTTP requests, so that is what the example refers to.

The v2 Box API is RESTful which you can read more about here and here.

In short, the folder id of the folder you're trying to get information about should be inserted in the resource URL where FOLDER_ID appears.

Your code sample indicates that you're developing in .NET, so I'd recommend using one of the REST libraries available for .NET, many of which are listed here. You may also find it helpful to utilize a REST client such as Postman for playing around with the API.

Другие советы

In simple terms, just ignore the way the examples are written in the BOX documentation. They just needed to display the information in a programming language independent way, in this case they chose the command line syntax.

-H refers to the header information you will be passing in when you make a HTTP request.

Not sure how it would be in .NET, but in PHP using the cURL library, it would be something like this:

$crl = curl_init();

curl_setopt($crl, CURLOPT_URL, 'https://www.box.com/api/2.0/folders/0');
curl_setopt($crl, CURLOPT_HTTPHEADER, array('Authorization: BoxAuth api_key=API_KEY&auth_token=AUTH_TOKEN',));
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);

$results = curl_exec($crl);

curl_close($crl);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top