0

I am trying to upload some documents to Box and create and retrieve a shared link for each of them. This is the code I am using for it, but I always retrieve 403:access_denied_insufficient_permissions. Any idea of why this is happening?

Hope you can help me! Thanks.

// CREATE THE FILE
BoxFileRequest req = new BoxFileRequest
{
    Name = zipFile.Name,
    Parent = new BoxRequestEntity { Id = newFolder.Id}
};
BoxFile uploadedFile = client.FilesManager.UploadAsync(req, stream).Result;

//REQUEST SHARED LINK
BoxSharedLinkRequest sharedLinkReq = new BoxSharedLinkRequest()
{
       Access = BoxSharedLinkAccessType.open,
       Permissions = new BoxPermissionsRequest
       {
             Download = BoxPermissionType.Open,
             Preview = BoxPermissionType.Open,
       }
};

BoxFile fileLink = fileManager.CreateSharedLinkAsync(uploadedFile.Id, sharedLinkReq).Result;
  • Do you own the folder? Are you the admin on the account? What type of account is this? There are a lot of security options in Box that will let the owner of the folder, or the enterprise admin lock some folders down so they are not "shareable" by open links. You might want to consider trying the "collaboration" APIs instead, since that only works for named users. – Peter Sep 04 '13 at 21:21

2 Answers2

1

you need to give the access token and url. I have use the Following code and in JSON Format you will get the Response. For more reference check the box API document

        HttpWebRequest httpWReq = HttpWebRequest)WebRequest.Create("https://api.box.com/2.0/folders/" + FolderID);
        ASCIIEncoding encoding = new ASCIIEncoding();
        string putData = "{\"shared_link\": {\"access\": \"open\"}}";
        byte[] data = encoding.GetBytes(putData);
        httpWReq.Method = "PUT";
        httpWReq.Headers.Add("Authorization", "Bearer ");
        httpWReq.ContentType = "application/json";
        httpWReq.ContentLength = data.Length;

Use the httpwebrequest PUT method after this. Mark it as Answer if its helpful.

1

It looks as if you are using the 3rd party BoxSync V2 API object. If you would like to just code to the API directly I had a similar issue that you are having. If you view this post you will see the answer. Here is the code I use and it works.

    string uri = String.Format(UriFiles, fileId);
    string response = string.Empty;
    string body = "{\"shared_link\": {\"access\": \"open\"}}";
    byte[] postArray = Encoding.ASCII.GetBytes(body);

    try
    {
        using (var client = new WebClient())
        {
            client.Headers.Add("Authorization: Bearer " + token);
            client.Headers.Add("Content-Type", "application/json");
            response = client.UploadString(uri, "PUT", body);
        }
    }
    catch (Exception ex)
    {
        return null;
    }
    return response;
Community
  • 1
  • 1
CodeChops
  • 1,980
  • 1
  • 20
  • 27
  • Just to be clear: my code does NOT return a null in the catch block. I log the error but have left out the code for this example. You too should do something with the error.. :) – CodeChops Apr 16 '14 at 14:44