Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the "search" API #93

Open
ale-rinaldi opened this issue Jun 5, 2024 · 4 comments
Open

Implement the "search" API #93

ale-rinaldi opened this issue Jun 5, 2024 · 4 comments

Comments

@ale-rinaldi
Copy link

There is a search API method that somehow was forgotten in documentation:

https://api.pcloud.com/search?query=holiday&offset=0&limit=600

It's used by the official frontend but is not mentioned in documentation; however it works correctly even when called with an OAuth authorization.

I think it's worth having it in the API clients.

@tomgross
Copy link
Owner

tomgross commented Jan 9, 2025

Hi @ale-rinaldi. Thanks for reaching out. You have several options:

  • Implement it yourself and submit a pull request.
  • Wait until I have time and interest to implement it.
  • Pay me (or someone else) to implement it. My contact details are on my homepage: https://tomgross.github.io/

If you use and ❤️ my software, consider buying me a coffee ☕ https://www.paypal.com/paypalme/tomgross42

@ikwyl6
Copy link

ikwyl6 commented Jan 29, 2025

If I could figure out how to import the pcloud api from directory/file (https://stackoverflow.com/questions/67631/how-can-i-import-a-module-dynamically-given-the-full-path) I would be able to write a PR for this to add it..I can add the pcloud module using above link but then it says (after some other errors...): ModuleNotFoundError: No module named 'pcloud.oauth2'; 'pcloud' is not a package when I try to run my script..

@ikwyl6
Copy link

ikwyl6 commented Jan 29, 2025

When I access search by adding it as a member of Tom's api with your query keyword above I get:

TypeError: PyCloud.search() got an unexpected keyword argument 'query'

I had to remove all keywords (query, offset, limit) to get a result.. When I do that I get a result back that lists the contents of my root folder only (no recursive - didn't try it) but looks like it gives a field called total that may be every file and folder your pcloud account regardless if it gives you only smaller subset results:

{'result': 0, 'total': 3077, 'items': [{....}, {...}, ...]}

search returns result, total, and items. This is similar to the metadata list of dicts for results that are part of the official pcloud api.

@ale-rinaldi If you can find for me any of the working keywords that will go with search, I'll put some more work into it to add as PR for this functionality. It will be very easy to add.

@ale-rinaldi
Copy link
Author

Hello @ikwyl6 ,

it's difficult to say without looking at your code, but it seems your error does not come from pCloud but from your code itself: it seems like you're calling a function with an argument that is not defined in the function declaration.

The search API is used for example by this Raycast extension: https://github.com/raycast/extensions/blob/a8f9bfbab28582353261c3c446c5526fda3a753d/extensions/pcloud/src/providers/SearchProvider.tsx

The URL parameters that it accepts are:

  • query: the text you're searching
  • iconformat: I honestly don't know, @xela92 may give us a hint?
  • access_token: the token to access the API as any other pCloud calls
  • offset: the number of items to skip
  • limit: the maximum number of results to return

The last to ones are typical for pagination: in the first call you usually start with offset 0 and a limit, 10 for example. If the user wants more items you do another call with offset 10 and limit 10; then with offset 20 and limit 10 and so on. This way you can get the items without doing a single, giant query.

That's the reason for the "total" field in the answer: if you limit the result, with "total" you can still know how much items you totally have to deal with.

Thanks for your effort ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants