Skip to main content
Question

Create Shared Links API Forbidden Error - .NET SDK

  • May 22, 2025
  • 2 replies
  • 42 views

Forum|alt.badge.img

Hi Everyone,

I am facing an issue while I am trying call Create Shared Links API via .NET SDK. The error thrown to me says: Box.V2.Exceptions.BoxAPIException: The API returned an error [Forbidden | skq87mh3ik4c7p75.1ca06a744043a75b4d195c44fed77a467] forbidden - Forbidden

 

The code I have been using for the same is as follows and the error happens in the last line of the code:

 

'Initialize Variables

Dim config As Box.V2.Config.IBoxConfig
Dim json,JSON_FilePath As String
Dim sdk As Box.V2.JWTAuth.BoxJWTAuth
Dim token As Threading.Tasks.Task(Of String)
Dim client As Box.V2.BoxClient
Dim folderInfo As Threading.Tasks.Task(Of Box.V2.Models.BoxCollection(Of Box.V2.Models.BoxItem))
Dim fileInfo As Threading.Tasks.Task(Of Box.V2.Models.BoxFile)
Dim sharedLinkRequest As Box.V2.Models.BoxSharedLinkRequest
Dim boxFile As Threading.Tasks.Task(Of Box.V2.Models.BoxFile)

'Read JSON Configuration File

JSON_FilePath = "<JWT_CONFIG_PATH>"

Using reader As StreamReader = New StreamReader(JSON_FilePath)
    
    json = reader.ReadToEnd
    
End Using


'Create BOX Configuration Object

config = Box.V2.Config.BoxConfig.CreateFromJsonString(json)

'Initialize SDK Client

sdk = New Box.V2.JWTAuth.BoxJWTAuth(config)
token = sdk.AdminTokenAsync()
client = sdk.AdminClient(token.Result.ToString)


folderInfo = client.FoldersManager.GetFolderItemsAsync("<FOLDER_ID>",10)


For Each item As Box.V2.Models.BoxItem In folderInfo.Result.Entries
    
        fileInfo = client.FilesManager.GetInformationAsync(item.Id)
        
        Console.WriteLine("Process for the file ID: "+fileInfo.Result.Id)
        sharedLinkRequest = New Box.V2.Models.BoxSharedLinkRequest()
        sharedLinkRequest.Access = Box.V2.Models.BoxSharedLinkAccessType.open
        sharedLinkRequest.Permissions = New Box.V2.Models.BoxPermissionsRequest()
        sharedLinkRequest.Permissions.Download = True
        sharedLinkRequest.Permissions.Edit = True

        boxFile = client.FilesManager.CreateSharedLinkAsync(fileInfo.Result.Id,sharedLinkRequest)
     
      Console.WriteLine(boxFile.Result.Name.ToString + " ----> " + boxFile.Result.SharedLink.Url.ToString)

Next

2 replies

Forum|alt.badge.img

Just to add few pointers, the service account which we are using for the app is having co-owner access to the folder path and is also having write permission as the app level.


Forum|alt.badge.img

Hi

Most likely the enterprise setting for shared links does not allow the EDIT permission. This can be changed in the Admin Console->Enterprise Settings->Content & Sharing
BOX1_X-u37RNDk8oFjRUM6JUf2Q.pngBest regards

Peter Christensen, Platform Solutions Engineer, Box