cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JavaScript - I can't get shared_link_already_exists.metadata

JavaScript - I can't get shared_link_already_exists.metadata

rweckey
Explorer | Level 3
Go to solution

Hi,

I want to create a shared link or get a shared link if it already exists with JavaScript.

 

If the shared link already exists, returned error has only '.tag'.

 

 

 

 

error: {
    error_summary: 'shared_link_already_exists/..',
    error: { '.tag': 'shared_link_already_exists' }
}

 

 

 

 

 

So I have no choice to use sharingListSharedLinks 

 

 

 

 

await dbx.sharingCreateSharedLinkWithSettings({
    path: fileId,
    settings: {
      access: 'viewer',
      audience: 'team'
    }
  }).then(res => {
    console.log(res.result.url);
  }).catch(async e =>{
    if(e.error.error['.tag'] === 'shared_link_already_exists'){
      console.log(e.error.error.shared_link_already_exists.metadata.url); // undefined
      await dbx.sharingListSharedLinks({
        path: fileId
      }).then((res) => {
        console.log(res.result.links[0].url);
      }).catch((e) => {    
      })
    }else{
    }
  })
})

 

 

 

 

 

But in API Explorer, error has metadata.url certainly.

 

Can you please tell me what caused this?

Thanks.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

The shared_link_already_exists error is not guaranteed to contain the metadata of the existing link, so you do need to have sharingListSharedLinks implemented for when the existing link is not returned. The shared_link_already_exists error may not the contain the metadata of the existing link if the requested settings do not match the settings of the existing link, for instance. Note that the existing link returned by sharingListSharedLinks may not have the same settings that you requested, so be sure to check that as needed.

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

The shared_link_already_exists error is not guaranteed to contain the metadata of the existing link, so you do need to have sharingListSharedLinks implemented for when the existing link is not returned. The shared_link_already_exists error may not the contain the metadata of the existing link if the requested settings do not match the settings of the existing link, for instance. Note that the existing link returned by sharingListSharedLinks may not have the same settings that you requested, so be sure to check that as needed.

Здравко
Legendary | Level 20
Go to solution

Hi @rweckey,

You're hitting in painful place of Dropbox API documentation - partial documenting. It's mentioned that "shared_link_already_exists" is optional field of the union, but no anything about what this depends on - that would let probability control. When exists, you can get the metadata, otherwise, as you have done, use link enumerations - least a bit optimization.

Let's hope the documentation will get improved.

rweckey
Explorer | Level 3
Go to solution

Thank you for your response.

 

The documentation states that shared_link_already_exists is optional, but I could not determine if this behavior is a feature or a bug.

It appears that "metadata" is not returned when the parameter "audience" is set.
I confirmed the same behavior in API Explorer. Sorry for the lack of confirmation.

I also understood that I must use sharingListSharedLinks and check the link setting.

 

It would be nice to have better documentation.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    rweckey Explorer | Level 3
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?