docs: Refactor documentation structure and add new guides#824
docs: Refactor documentation structure and add new guides#824patrikbraborec wants to merge 3 commits intomasterfrom
Conversation
Reorganized documentation into a clearer three-tier structure: - 01_introduction: Overview, installation, and quick start - 02_concepts: Core concepts like authentication, client architecture, error handling, retries, pagination, and nested clients - 03_guides: Practical guides for common use cases Added comprehensive new documentation: - Authentication guide with API token management - Client architecture explanation - Error handling and retry strategies - Dataset retrieval guide Updated sidebar navigation to reflect the new structure. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
janbuchar
left a comment
There was a problem hiding this comment.
I like the direction this is going!
|
|
||
| ## Authentication and Initialization | ||
|
|
||
| To use the client, you need an [API token](https://docs.apify.com/platform/integrations/api#api-token). You can find your token under [Integrations](https://console.apify.com/account/integrations) tab in Apify Console. Copy the token and initialize the client by providing the token (`MY-APIFY-TOKEN`) as a parameter to the `ApifyClient` constructor. |
There was a problem hiding this comment.
Does this use copy from the original guide or is it generated anew? I think it could use some proofreading - I'd expect a "the" before "Integrations tab", and I've seen several other grammar issues in this doc.
|
|
||
| :::note Resource identification | ||
|
|
||
| The resource ID can be either the `id` of the said resource, or a combination of your `username/resource-name`. |
There was a problem hiding this comment.
I believe this only applies to Actors?
| const myActor = await actorClient.get(); | ||
| // Starts the run of john-doe/my-actor and returns the Run object. | ||
| const myActorRun = await actorClient.start(); | ||
| ``` |
There was a problem hiding this comment.
Maybe link to client architecture concepts page from here for a more detailed description?
| description: 'Get started with the Apify client for JavaScript by running your first Actor and retrieving results.' | ||
| --- | ||
|
|
||
| Learn how to start Actors and retrieve their results using the Apify Client. |
There was a problem hiding this comment.
The guide should make it clear that the client essentially allows doing everything you can do in the console, and running Actors and fetching the results is just the tip of the iceberg.
|
|
||
| ## Step 2: Running your first Actor | ||
|
|
||
| To start an Actor, you need its ID (e.g., `john-doe/my-cool-actor`) and an API token. The Actor's ID is a combination of the Actor name and the Actor owner's username. Use the [`ActorClient`](/reference/class/ActorClient) to run the Actor and wait for it to complete. You can run both your own Actors and [Actors from Apify Store](https://docs.apify.com/platform/actors/running/actors-in-store). |
There was a problem hiding this comment.
It's worth mentioning that the API tab in the store gives you a code snippet for running that specific Actor - https://apify.com/apify/website-content-crawler/api/javascript
| if (result.retryable) { | ||
| // Implement retry logic | ||
| console.log('This error is retryable. Consider retrying...'); | ||
| } |
There was a problem hiding this comment.
I'd just drop this - at this point, the client already retried the request extensively.
| } | ||
| ``` | ||
|
|
||
| ## Retry Logic with Exponential Backoff |
There was a problem hiding this comment.
This section is unnecessary, the client does this out of the box.
| ## Validation Errors | ||
|
|
||
| The API returns validation errors when input doesn't meet requirements: | ||
|
|
||
| ```js | ||
| try { | ||
| await client.actors().create({ | ||
| // Missing required 'name' field | ||
| }); | ||
| } catch (error) { | ||
| if (error.statusCode === 400) { | ||
| console.error('Validation error:', error.message); | ||
| // Handle validation failure | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Graceful Degradation | ||
|
|
||
| Implement graceful degradation for non-critical operations: | ||
|
|
||
| ```js | ||
| async function getActorWithFallback(actorId) { | ||
| try { | ||
| return await client.actor(actorId).get(); | ||
| } catch (error) { | ||
| console.warn(`Failed to fetch actor: ${error.message}`); | ||
|
|
||
| // Return fallback data | ||
| return { | ||
| id: actorId, | ||
| name: 'Unknown Actor', | ||
| unavailable: true | ||
| }; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Debugging Tips | ||
|
|
||
| Enable detailed logging to debug errors: | ||
|
|
||
| ```js | ||
| const client = new ApifyClient({ | ||
| token: 'MY-APIFY-TOKEN', | ||
| // Add custom request interceptor for debugging | ||
| }); | ||
|
|
||
| try { | ||
| await client.actor('my-actor').start(); | ||
| } catch (error) { | ||
| // Log full error details | ||
| console.error('Full error:', JSON.stringify({ | ||
| message: error.message, | ||
| statusCode: error.statusCode, | ||
| type: error.type, | ||
| clientMethod: error.clientMethod, | ||
| path: error.path, | ||
| stack: error.stack | ||
| }, null, 2)); | ||
| } | ||
| ``` |
There was a problem hiding this comment.
This is also just filler - the docs don't exist to lecture people on the general principles of working with HTTP APIs in Javascript
| title: 'Pagination' | ||
| --- | ||
|
|
||
| Most methods named `list` or `listSomething` return a [`Promise<PaginatedList>`](/reference/interface/PaginatedList). |
There was a problem hiding this comment.
The return values also typically return an AsyncIterator so you can just use a for await (...) loop without worrying about pagination.
| --- | ||
|
|
||
| The fastest way to get results from an Actor is to pass input directly to the `call` function. | ||
| Input can be passed to `call` function and the reference of running Actor (or wait for finish) is available in `runData` variable. |
There was a problem hiding this comment.
Again, would be great to mention the API tab in the Store - the snippets include a prefilled input object, which is nice
Summary
Test plan
🤖 Generated with Claude Code