### Install Picnic-API Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Install the picnic-api package using npm. ```bash npm install picnic-api ``` -------------------------------- ### Usage Examples Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Demonstrates common use cases for the Picnic API client, such as searching for products, managing the cart, and retrieving delivery information. ```APIDOC ## Usage examples ```ts // Search for products const results = await picnicClient.catalog.search("Affligem blond"); // Add a product to the cart await picnicClient.cart.addProductToCart(11295810, 2); // Bulk add products to the cart await picnicClient.cart.addProductsToCart([ { productId: "s11295810", quantity: 2 }, { productId: "s10000123", quantity: 1 }, ]); // Get available delivery slots const slots = await picnicClient.cart.getDeliverySlots(); // Get details of a specific delivery const delivery = await picnicClient.delivery.getDelivery("delivery-id"); ``` ``` -------------------------------- ### Get Available Delivery Slots Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Retrieve a list of available delivery slots for the user's location. ```typescript // Get available delivery slots const slots = await picnicClient.cart.getDeliverySlots(); ``` -------------------------------- ### Example of a Dynamically Constructed Endpoint Action Source: https://github.com/mrvdh/picnic-api/blob/main/AGENTS.md This object represents a dynamically constructed endpoint action, often found within embedded JavaScript expressions in PML/Fusion pages. It specifies the action type, HTTP method, URL, and request body. ```javascript { actionType: "ENDPOINT", method: "post", url: "pages/task/recipe-saving", body: { payload: { recipe_id, saved_at: "" } } } ``` -------------------------------- ### Get Specific Delivery Details Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Fetch detailed information about a particular delivery using its unique delivery ID. ```typescript // Get details of a specific delivery const delivery = await picnicClient.delivery.getDelivery("delivery-id"); ``` -------------------------------- ### Build and Run Commands Source: https://github.com/mrvdh/picnic-api/blob/main/AGENTS.md Provides essential commands for setting up dependencies and running the playground file for API testing. ```bash npm install # Install dependencies npx ts-node playground.ts # Run the playground file ``` -------------------------------- ### Initialize Picnic Client Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Import and create a new instance of the PicnicClient. Optional configuration parameters include countryCode, apiVersion, authKey, and a custom URL. ```typescript import PicnicClient from "picnic-api"; const picnicClient = new PicnicClient({ countryCode: "NL", // The country code for the API. Options: "NL" (default) or "DE". apiVersion: "15", // The API version (default "15"). authKey: "...", // An existing auth key to skip the login step. url: "...", // A custom base URL (defaults to https://storefront-prod..picnicinternational.com/api/). }); ``` -------------------------------- ### Project Structure Overview Source: https://github.com/mrvdh/picnic-api/blob/main/AGENTS.md Illustrates the domain-based architecture of the codebase, detailing the purpose of each directory and file within the `src` folder. ```tree src/ index.ts # PicnicClient class — extends HttpClient with all domain services http-client.ts # Base HTTP client — handles request construction, auth headers, errors types/ common.ts # Shared types (ApiConfig, CountryCode, etc.) fusion.ts # Types for Fusion/PML page responses domains/ app/ # Bootstrap data, pages, announcements auth/ # Login/authentication cart/ # Cart management, delivery slots, checkout catalog/ # Search, suggestions, product lists consent/ # User consent management content/ # Content pages customer-service/ # Support tickets, contact options delivery/ # Delivery status, scenarios payment/ # Payment methods, billing recipe/ # Recipes, cookbook user/ # User details, profile, settings user-onboarding/ # Onboarding flows ``` -------------------------------- ### Search for Products Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Use the catalog service to search for products by name. ```typescript // Search for products const results = await picnicClient.catalog.search("Affligem blond"); ``` -------------------------------- ### Add Product to Cart Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Add a specific product to the shopping cart using its product ID and desired quantity. ```typescript // Add a product to the cart await picnicClient.cart.addProductToCart(11295810, 2); ``` -------------------------------- ### Authentication Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Obtain an authentication key to access protected endpoints. The key is automatically stored and sent with subsequent requests. If you already have a key, you can provide it during client initialization. ```APIDOC ## Authentication Most endpoints require authentication. Call `auth.login()` to obtain an auth key, which is automatically stored in the client and sent with subsequent requests. If you already have a key from a previous session, pass it as `authKey` in the constructor instead. ```ts await picnicClient.auth.login("email", "password"); ``` ``` -------------------------------- ### Bulk Add Products to Cart Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Efficiently add multiple products to the cart by providing an array of objects, each containing a productId and quantity. ```typescript // Bulk add products to the cart await picnicClient.cart.addProductsToCart([ { productId: "s11295810", quantity: 2 }, { productId: "s10000123", quantity: 1 }, ]); ``` -------------------------------- ### Custom Requests Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Allows making direct HTTP requests for endpoints not yet covered by the domain services. You can specify the HTTP method and the route, along with an optional request body. ```APIDOC ## Custom requests For endpoints not yet covered by a domain service, use `sendRequest` directly: ```ts await picnicClient.sendRequest("GET", "/unknown/route"); await picnicClient.sendRequest("POST", "/invite/friend", { email: "friend@example.com" }); ``` ``` -------------------------------- ### Authenticate with Picnic API Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Log in to obtain an authentication key, which is automatically stored and used for subsequent requests. Alternatively, provide an existing authKey during client initialization. ```typescript await picnicClient.auth.login("email", "password"); ``` -------------------------------- ### Make Custom API Requests Source: https://github.com/mrvdh/picnic-api/blob/main/README.md Utilize the sendRequest method for direct interaction with API endpoints not yet exposed by domain services. Specify the HTTP method and route, optionally including a request body. ```typescript await picnicClient.sendRequest("GET", "/unknown/route"); await picnicClient.sendRequest("POST", "/invite/friend", { email: "friend@example.com" }); ``` -------------------------------- ### HttpClient.sendRequest Signature Source: https://github.com/mrvdh/picnic-api/blob/main/AGENTS.md Defines the signature for the `sendRequest` method, detailing parameters for HTTP method, path, request data, and header inclusion. Use `includePicnicHeaders` to add `x-picnic-agent` and `x-picnic-did` headers when necessary. ```typescript sendRequest( method: "GET" | "POST" | "PUT" | "DELETE", // HTTP method path: string, // API path, e.g. `/cart` data: TRequestData | null = null, // Request body (for POST/PUT) includePicnicHeaders: boolean = false, // When true, adds x-picnic-agent and x-picnic-did headers isImageRequest: boolean = false, // When true, returns ArrayBuffer instead of JSON ): Promise ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.