Hi team,
I'm very new to Box api/sdk; my client has an enterprize account with box and our new application needs to upload files to box via dot net sdk.
I was able to upload file using the "developer key" which I got from the box UI; but I'm not sure how to get this key programatically so that I dont have to worry about the key expiry.
This is what I did:
*****************************************************************************************
var privateKey = File.ReadAllText(my_key_path);
var boxConfig = new BoxConfig(clientId, clientSecret, entId, privateKey, jwtKeyPassword, kid);
var boxJWT = new BoxJWTAuth(boxConfig);
var adminToken = boxJWT.AdminToken();
var client = boxJWT.AdminClient(adminToken);
//var session = new OAuthSession(adminToken, "", 3600, "bearer");
//var client = new BoxClient(boxConfig, session);
BoxFile f;
using (FileStream fs = File.Open(my_file_path, FileMode.Open, FileAccess.Read))
{
BoxFileRequest request = new BoxFileRequest()
{
Name = "New File",
Parent = new BoxRequestEntity() { Id = "0" }
};
f = await client.FilesManager.UploadAsync(request, fs);
}
return f.Id;
*****************************************************************************************
When I execute this, Im getting error saying insufficient privilege for the provided access token.
But if I use the commented out lines instead, with the developer key, thsi works fine:
var session = new OAuthSession(dev_key_from_box_ui, "", 3600, "bearer");
var client = new BoxClient(boxConfig, session);
Could you guys please help me out?
Regards,
Kiran