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.

Discuss Dropbox Developer & API

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

getting changes after Webhook

getting changes after Webhook

webrobert
Explorer | Level 3
Go to solution

Hello devs, 

 

I am having an issue getting changes to files [after changing to a business account]

 

Before I was using the  `files/list_folder` endpoint. 

 

But now I can't seem to get it to list changes in the team only the user folder.

return Http::withToken(cache()->get('dropbox_token'))
->withHeaders(['Dropbox-API-Select-Admin' => '<admin_member_id>'])
->post('https://api.dropboxapi.com/2/files/list_folder', [
'include_deleted' => true,
'include_has_explicit_shared_members' => false,
'include_non_downloadable_files' => false,
'path' => '',
'recursive' => true
])
->json();

 I also tried the team endpoint but it doesn't list changes just shows the team space.

 

return Http::withToken(cache()->get('dropbox_token'))
->withBody('{}', 'application/json')
->post('https://api.dropboxapi.com/2/team/team_folder/list')
->json();

 

 

I am wanting to act on files that are changed within <team_root>/stores/

 

 What am I missing?

1 Accepted Solution

Accepted Solutions

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

Hi @webrobert,

First of all, using list_folder alone, will never get the changes alone! Is this ever worked (on any account type)? I don't think so.

You need to keep the last cursor cached and when some change comes in, you can "continue" with changes only. 😉

 


@webrobert wrote:

...

I am having an issue getting changes to files [after changing to a business account]

...


Did you set your root namespace? 🤔 I can't see such things in the code you posted. Account root space and the home space coincide for personal account and for team account without spaces, but are different things when you're using team spaces. If not set explicitly, the home space is in use.

Hope this gives direction.

View solution in original post

5 Replies 5

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

Hi @webrobert,

First of all, using list_folder alone, will never get the changes alone! Is this ever worked (on any account type)? I don't think so.

You need to keep the last cursor cached and when some change comes in, you can "continue" with changes only. 😉

 


@webrobert wrote:

...

I am having an issue getting changes to files [after changing to a business account]

...


Did you set your root namespace? 🤔 I can't see such things in the code you posted. Account root space and the home space coincide for personal account and for team account without spaces, but are different things when you're using team spaces. If not set explicitly, the home space is in use.

Hope this gives direction.

webrobert
Explorer | Level 3
Go to solution

@Здравко, legend. Thank you. Root name space. did it.  

 

Yes, cache and go. Here is my Laravel solution using listFolderContinue() to retrieve or create a cache of the cursor.

public function listFolderContinue()
{
$cursor = cache()->rememberForever('dropbox_stores_cursor', function () {
return $this->listFolder()['cursor'];
});

$response = Http::withToken(cache()->get('dropbox_token'))
->withHeaders([
'Dropbox-API-Select-Admin' => '<member_id>',
'Dropbox-API-Path-Root' => '{".tag": "root", "root": "<id_of_root>"}'
])
->post('https://api.dropboxapi.com/2/files/list_folder/continue', compact('cursor'))
->json();

if ($response['cursor']) {
cache()->put('dropbox_stores_cursor', $response['cursor']);
}

return $response;
}

public function listFolder()
{
return Http::withToken(cache()->get('dropbox_token'))
->withHeaders([
'Dropbox-API-Select-Admin' => '<member_id>',
  'Dropbox-API-Path-Root' => '{".tag": "root", "root": "<id_of_root>"}'
])
->post('https://api.dropboxapi.com/2/files/list_folder', [
'include_deleted' => true,
'include_has_explicit_shared_members' => false,
'include_non_downloadable_files' => false,
'path' => '/Stores',
'recursive' => true
])
->json();
}

 

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

Hi again @webrobert,

Just to note some corner cases and some ways your code may get more stable.

Starting with listing and immediately continue that listing can lead to some inconsistencies at the beginning. If your initial listing "eat" the entire number of entries then the continuation wont return anything - the listing would already have processed all changes and you lost them. In opposite case - if you have too many files and the initial listing cannot get to all of them then many files will become recognized as changes while they are NOT actually - just entries left from the list.

Sometimes /2/files/list_folder/continue may not be able return any/all changes immediately. The changes aren't lost, but they will likely be returned on the next event - i.e. processing delay.

 

So to avoid any initialization issues, instead of within the processing body, better make the initial cache in your service initialization part and not using /2/files/list_folder, but rather jump to the end using /2/files/list_folder/get_latest_cursor. 😉 Isn't simpler? ... and stable!

You never check the 'has_more' flag! Check it out to avoid missing some entries, for variety of reasons, and do get in loop while this flag is set. In such a way there is no risk to delay processing of any entries.

Good luck.

Greg-DB
Dropbox Staff
Go to solution

For reference for anyone looking for information on setting the root, please refer to the Team Files Guide.

webrobert
Explorer | Level 3
Go to solution

@Здравко 

 

Ahh, makes sense. Yes, I did notice there was an edge there that would "eat" files. I dont fully follow the revised solution, but ill read up on using the other endpoint. Stay tuned...

Need more support?
Who's talking

Top contributors to this post

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