Shared_link is null

新規投稿

コメント

6件のコメント

  • Brent

    Hello !

     

    Thanks for submitting your question to the Box Developer Community. As you've observed in the Box Web App, when a file is uploaded to Box, a Shared Link is not created until you click the Share option. In other words, a Shared Link is only created when you action the request to create the link. Our API functions similarly. After you upload the content to Box, you will want to execute an additional PUT call to create the shared link. The specific action is documented here: https://developer.box.com/reference#create-or-update-shared-link

     

    Best,

    Brent

    0
    コメントアクション パーマリンク
  • hyperlinked

    I'm having this problem too and I'm specifically making a PUT request to create the shared link, but any further calls to the API will continue to result in a null value for the shared_link data until I physically go to the file in question via the Web interface and view the sharing settings. I don't need to save anything. I just need to view it. 

     

    The usual order of events goes something like this.

     

    1) My API Client performs a Get File Info request.

    2) The shared_link data is null so I perform a follow-up request to update the file's settings.

    3) My API Client performs an Update Shared Link request. The response I get from Box is something like this:

    {"type":"file","id":"***number removed for privacy***0","etag":"10","shared_link":null} 

    4) Any subsequent request of Get File Info continues to return a null result for the shared_link data, but I know my PUT request was executed because...

    5) If I go look at the file over the Web interface and click on the Share button and inspect the settings, I'll see that the link is how set to allow anyone with the link to download it and the sharing link icon indicator now appears next to the title of the document in the header of the page.

    6) I go back and have my API Client perform another Get File Info request and this time the shared_link data appears.

     

    It seems like the API responses I'm getting are cached or are frozen until I manually go to the file's page and click on the Share button to inspect my changes. If I just visit that page it won't work. I have to visit the page and inspect the share settings. 

     

    I've also tried waiting several minutes to see if I get a different response from the API. No dice.

     

    I haven't tried waiting hours yet, but so far it seems the key to getting the data I want is to basically update the sharing settings via the Web interface anyway which completely defeats the purpose of me executing this over the API.

     

    Am I doing something wrong? Is there a command to flush the API state so I can get updated file info?

    0
    コメントアクション パーマリンク
  • hyperlinked

    Ok, I sort of figured out my issue. 

     

    I don't think my attempt to update the shared_link data worked. I just realized that merely clicking on the Share button for the link in question causes the sharing settings to be updated so that would explain why the shared_link continues to fail to show up for me via the API. The request wasn't successful. 

     

    This is no longer an issue for me because I decided to just call the file download endpoint instead of retrieving the shared_link url to get a persistent download URL first before retrieving the file. 

    0
    コメントアクション パーマリンク
  • GhastlyParadox

    I'm experiencing the same issue. Calling the download endpoint works to create the shared links, but it's definitely not ideal, particularly when dealing with a large number of files. Hoping to find a way around having to download them.

    0
    コメントアクション パーマリンク
  • GhastlyParadox

    Update: updating the folder's share settings first via the API (instead of the web app) seems to work. Then I was able to update the share settings for each individual file via update_info - perhaps because updating the folder via the API (for some reason) creates the shared_link object for the individual items? Not sure.

     

    In any case, I simply wanted to share a folder containing images, and enable open access to the files, so to generate direct links to them. I started over with a new folder, set everything via the API, and it worked. 

     

    folder = client.folder(folder_id='your_folder_id').update_info(data={
        'shared_link': {
            'access': 'open'
        }
      }).get_items()
    
    for image in folder:
      image = client.file(image.id).get().update_info(data={
          'shared_link': {
              'access': 'open'
          }
      })
    url = image.shared_link['download_url'] 

     

    0
    コメントアクション パーマリンク
  • jhession

    UPDATE: I GOT IT WORKING.

     

    Using php and Guzzle, I was originally trying the following:

     

     

    $api_url = '.....://api.box.com/2.0/files/' . $fileid;
    $query = ['fields' => 'shared_link'];
    $shared_link = [
      'access' => 'company', 
      'password' => null
    ];
    $params = [
      'headers' => $header, 
      'query' => $query, 
      'shared_link' => $shared_link
    ];
    $response = json_decode(
      $client->request('PUT', $api_url, $params)->getBody()->getContents()
    );
    $shared_link = $response->shared_link->url;

     

    While this was not throwing an error, it was not updating the shared link. What I realized is that for a PUT request I need to send JSON, not a php object. Guzzle has a "json" parameter for this. The new code...

    $api_url = '.....://api.box.com/2.0/files/' . $response->entries[0]->id;
    $query = ['fields' => 'shared_link'];
    $json = ['shared_link' => ['access' => 'company']];
    $params = [
      'headers' => $header, 
      'query' => $query, 
      'json' => $json
    ];
    $response = json_decode(
      $client->request('PUT', $api_url, $params)->getBody()->getContents()
    );
    $shared_link = $response->shared_link->url;

     

     

    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。