Last active
August 29, 2015 14:10
-
-
Save cburnette/3e681c4984f5751b6162 to your computer and use it in GitHub Desktop.
Call the Box API without using the Box .NET SDK (i.e. you only have VS 2010)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using RestSharp; | |
using System; | |
using System.Collections.Generic; | |
using System.Dynamic; | |
using System.Linq; | |
using System.Text; | |
//install NuGet package 'RestSharp' | |
//install NuGet package Json.NET' | |
namespace Box_API_Rest_Example | |
{ | |
class Program | |
{ | |
const string DEVELOPER_TOKEN = "{YOUR_DEVELOPER_TOKEN}"; | |
const string BASE_URL = "https://api.box.com/2.0"; | |
//for this example program just click on a folder in Box and extract the folder ID from the URL | |
const string FOLDER_ID = "2764335289"; | |
static void Main() | |
{ | |
var client = new RestClient(BASE_URL); | |
client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(DEVELOPER_TOKEN, "Bearer"); | |
var request = new RestRequest("folders/{id}", Method.PUT); | |
request.AddUrlSegment("id", FOLDER_ID); | |
dynamic sharedLinkAttributes = new ExpandoObject(); | |
sharedLinkAttributes.access = "open"; | |
dynamic sharedLink = new ExpandoObject(); | |
sharedLink.shared_link = sharedLinkAttributes; | |
request.AddJsonBody(sharedLink); | |
var response = client.Execute(request); | |
var content = response.Content; | |
dynamic parsed_content = JObject.Parse(content); | |
string shared_link_url = parsed_content.shared_link.url; | |
Console.WriteLine("Shared Link URL: {0}", shared_link_url); | |
Console.WriteLine("Press Return to exit..."); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment