### Install Node-Bring-Shopping Source: https://github.com/foxriver76/node-bring-api/blob/master/README.md Installs the 'bring-shopping' package using npm. The `--production` flag ensures that only production dependencies are installed, which is suitable for deployment. ```bash npm install bring-shopping --production ``` -------------------------------- ### Shopping List Workflow Example Source: https://context7.com/foxriver76/node-bring-api/llms.txt Demonstrates a complete workflow including authentication, loading lists, adding items, retrieving items, marking items as purchased, and loading translations. ```APIDOC ## Full Workflow Example ### Description A full example demonstrating typical usage patterns including authentication, list management, and item operations. ### Authentication - Initialize the Bring API client with user credentials. - Call the `login()` method to authenticate. ### List Management - Use `loadLists()` to retrieve all shopping lists associated with the authenticated user. - Use `saveItem(listUuid, name, spec)` to add a new item to a specific list. - Use `getItems(listUuid)` to retrieve all items currently in a list. - Use `moveToRecentList(listUuid, itemName)` to mark an item as purchased. ### Translation Loading - Use `loadTranslations(locale)` to fetch translated item names for a given locale. ### Example Usage ```javascript const Bring = require('bring-shopping'); async function shoppingListWorkflow() { // Initialize and authenticate const bring = new Bring({ mail: 'user@example.com', password: 'your-password' }); try { await bring.login(); console.log(`Welcome, ${bring.name}!\n`); } catch (error) { console.error(`Authentication failed: ${error.message}`); return; } try { // Get all shopping lists const { lists } = await bring.loadLists(); console.log(`Found ${lists.length} shopping list(s)`); if (lists.length === 0) { console.log('No lists found'); return; } // Work with the first list const myList = lists[0]; console.log(`\nWorking with list: "${myList.name}"`); // Add items to the list const itemsToAdd = [ { name: 'Milk', spec: '2% organic' }, { name: 'Bread', spec: 'sourdough' }, { name: 'Apples', spec: '6 Honeycrisp' } ]; for (const item of itemsToAdd) { await bring.saveItem(myList.listUuid, item.name, item.spec); console.log(`Added: ${item.name} (${item.spec})`); } // Get current items const items = await bring.getItems(myList.listUuid); console.log(`\nCurrent shopping list (${items.purchase.length} items):`); items.purchase.forEach(item => { const spec = item.specification ? ` - ${item.specification}` : ''; console.log(` [ ] ${item.name}${spec}`); }); // Mark an item as purchased await bring.moveToRecentList(myList.listUuid, 'Milk'); console.log('\nMarked "Milk" as purchased'); // Load translations for display const translations = await bring.loadTranslations('de-DE'); console.log(`\nItem translations loaded (${Object.keys(translations).length} items)`); } catch (error) { console.error(`Error: ${error.message}`); } } shoppingListWorkflow(); ``` ``` -------------------------------- ### Node.js Bring! API Usage Example Source: https://github.com/foxriver76/node-bring-api/blob/master/README.md Demonstrates how to use the 'bring-shopping' Node.js module to interact with the Bring! API. It covers logging in with user credentials, loading all shopping lists, retrieving items from a specific list using its UUID, and loading translations. ```javascript const bringApi = require(`bring-shopping`); main(); async function main () { // provide user and email to login const bring = new bringApi({mail: `example@example.com`, password: `secret`}); // login to get your uuid and Bearer token try { await bring.login(); console.log(`Successfully logged in as ${bring.name}`); } catch (e) { console.error(`Error on Login: ${e.message}`); } // get all lists and their listUuid const lists = await bring.loadLists(); // get items of a list by its list uuid const items = await bring.getItems('9b3ba561-02ad-4744-a737-c43k7e5b93ec'); // get translations const translations = await bring.loadTranslations('de-DE'); } ``` -------------------------------- ### Get User Settings (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Retrieves the current user's general settings and list-specific settings. This function requires an authenticated Bring! client. The response includes user settings like theme and notifications, as well as list settings such as default sections for users. ```javascript const bring = await authenticate(); try { const settings = await bring.getUserSettings(); // settings = { // userSettings: [ // { key: 'theme', value: 'dark' }, // { key: 'notifications', value: 'true' } // ], // userlistsettings: [ // { // listUuid: '9b3ba561-வுகளை', // usersettings: [ // { key: 'defaultSection', value: 'produce' } // ] // } // ] // } console.log('User settings:'); settings.userSettings.forEach(s => { console.log(` ${s.key}: ${s.value}`); }); } catch (error) { console.error(`Failed to get settings: ${error.message}`); } ``` -------------------------------- ### Get Item Details from Shopping List (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Retrieves detailed information for all items within a specified shopping list. It requires an authenticated Bring! client and the list's UUID. The output includes item UUIDs, assigned users, and image URLs. ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { const details = await bring.getItemsDetails(listUuid); // details = [ // { // uuid: 'item-uuid-123', // itemId: 'Milk', // listUuid: '9b3ba561-02ad-4744-a737-c43k7e5b93ec', // userIconItemId: 'milk-icon', // userSectionId: 'dairy', // assignedTo: 'user-uuid-456', // imageUrl: 'https://...' // } // ] details.forEach(item => { console.log(`Item: ${item.itemId} (UUID: ${item.uuid})`); if (item.assignedTo) { console.log(` Assigned to: ${item.assignedTo}`); } if (item.imageUrl) { console.log(` Image: ${item.imageUrl}`); } }); } catch (error) { console.error(`Failed to get item details: ${error.message}`); } ``` -------------------------------- ### Get Users from a Specific Shopping List using JavaScript Source: https://context7.com/foxriver76/node-bring-api/llms.txt Gets all users who have access to a specific shopping list, identified by its UUID. Returns user information including name, email, and settings. This function requires an authenticated 'bring' instance and a valid listUuid. ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { const response = await bring.getAllUsersFromList(listUuid); // response.users = [ // { // publicUuid: 'abc123', // name: 'John Doe', // email: 'john@example.com', // photoPath: '/photos/abc123.jpg', // pushEnabled: true, // plusTryOut: false, // country: 'DE', // language: 'de-DE' // } // ] response.users.forEach(user => { console.log(`User: ${user.name} (${user.email})`); }); } catch (error) { console.error(`Failed to get users: ${error.message}`); } ``` -------------------------------- ### Get Pending Invitations (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Fetches all pending invitations to share shopping lists that have been sent to the current user. This function requires an authenticated Bring! client. The response contains an array of invitation objects. ```javascript const bring = await authenticate(); try { const response = await bring.getPendingInvitations(); // response = { invitations: [...] } if (response.invitations.length === 0) { console.log('No pending invitations'); } else { response.invitations.forEach(invite => { console.log(`Invitation: ${JSON.stringify(invite)}`); }); } } catch (error) { console.error(`Failed to get invitations: ${error.message}`); } ``` -------------------------------- ### Complete Shopping List Workflow (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Demonstrates a full workflow including authentication, loading shopping lists, adding items, marking items as purchased, and loading translations. Requires user credentials. ```javascript const Bring = require('bring-shopping'); async function shoppingListWorkflow() { // Initialize and authenticate const bring = new Bring({ mail: 'user@example.com', password: 'your-password' }); try { await bring.login(); console.log(`Welcome, ${bring.name}!\n`); } catch (error) { console.error(`Authentication failed: ${error.message}`); return; } try { // Get all shopping lists const { lists } = await bring.loadLists(); console.log(`Found ${lists.length} shopping list(s)`) if (lists.length === 0) { console.log('No lists found'); return; } // Work with the first list const myList = lists[0]; console.log(`\nWorking with list: "${myList.name}"`); // Add items to the list const itemsToAdd = [ { name: 'Milk', spec: '2% organic' }, { name: 'Bread', spec: 'sourdough' }, { name: 'Apples', spec: '6 Honeycrisp' } ]; for (const item of itemsToAdd) { await bring.saveItem(myList.listUuid, item.name, item.spec); console.log(`Added: ${item.name} (${item.spec})`); } // Get current items const items = await bring.getItems(myList.listUuid); console.log(`\nCurrent shopping list (${items.purchase.length} items):`); items.purchase.forEach(item => { const spec = item.specification ? ` - ${item.specification}` : ''; console.log(` [ ] ${item.name}${spec}`); }); // Mark an item as purchased await bring.moveToRecentList(myList.listUuid, 'Milk'); console.log('\nMarked "Milk" as purchased'); // Load translations for display const translations = await bring.loadTranslations('de-DE'); console.log(`\nItem translations loaded (${Object.keys(translations).length} items)`); } catch (error) { console.error(`Error: ${error.message}`); } } shoppingListWorkflow(); ``` -------------------------------- ### Load Product Catalog (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Loads the complete product catalog for a given locale, organized into sections and categories. This function requires authentication. ```javascript const bring = await authenticate(); try { const catalogData = await bring.loadCatalog('de-DE'); // catalogData = { // language: 'de-DE', // catalog: { // sections: [ // { // sectionId: 'dairy', // name: 'Milchprodukte', // items: [ // { itemId: 'Milk', name: 'Milch' }, // { itemId: 'Cheese', name: 'Käse' } // ] // }, // { // sectionId: 'produce', // name: 'Obst & Gemüse', // items: [...] // } // ] // } // } console.log(`Catalog language: ${catalogData.language}`); catalogData.catalog.sections.forEach(section => { console.log(`\n${section.name}:`); section.items.slice(0, 3).forEach(item => { console.log(` - ${item.name} (${item.itemId})`); }); }); } catch (error) { console.error(`Failed to load catalog: ${error.message}`); } ``` -------------------------------- ### loadCatalog(locale) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Loads the complete product catalog for a locale, organized by sections (categories). ```APIDOC ## POST /catalog ### Description Loads the complete product catalog for a locale, organized by sections. ### Method POST ### Endpoint /catalog ### Parameters #### Query Parameters - **locale** (string) - Required - The locale for which to load the catalog (e.g., 'de-DE'). ### Request Example ```json { "locale": "de-DE" } ``` ### Response #### Success Response (200) - **language** (string) - The locale of the catalog. - **catalog** (object) - Contains catalog data organized into sections. - **sections** (array) - An array of catalog sections. - **sectionId** (string) - The unique identifier for the section. - **name** (string) - The display name of the section. - **items** (array) - An array of items within the section. - **itemId** (string) - The unique identifier for the item. - **name** (string) - The display name of the item. #### Response Example ```json { "language": "de-DE", "catalog": { "sections": [ { "sectionId": "dairy", "name": "Milchprodukte", "items": [ { "itemId": "Milk", "name": "Milch" }, { "itemId": "Cheese", "name": "Käse" } ] } ] } } ``` ``` -------------------------------- ### Load Shopping Lists using JavaScript Source: https://context7.com/foxriver76/node-bring-api/llms.txt Retrieves all shopping lists associated with the authenticated user. Returns an array of list objects, each containing listUuid, name, and theme. This function assumes prior authentication. ```javascript const bring = await authenticate(); try { const response = await bring.loadLists(); // response.lists = [ // { listUuid: '9b3ba561-02ad-4744-a737-c43k7e5b93ec', name: 'Groceries', theme: 'default' }, // { listUuid: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', name: 'Party Shopping', theme: 'party' } // ] response.lists.forEach(list => { console.log(`List: ${list.name} (UUID: ${list.listUuid})`); }); } catch (error) { console.error(`Failed to load lists: ${error.message}`); // Possible error: "Cannot get lists: JWT access token is not valid" } ``` -------------------------------- ### Authenticate with Bring! API using JavaScript Source: https://context7.com/foxriver76/node-bring-api/llms.txt Authenticates with the Bring! API using email and password credentials. This method must be called before any other API methods. It stores the bearer token and user UUID internally for subsequent requests. Requires the 'bring-shopping' package. ```javascript const Bring = require('bring-shopping'); async function authenticate() { const bring = new Bring({ mail: 'user@example.com', password: 'your-password' }); try { await bring.login(); console.log(`Logged in as: ${bring.name}`); // bring.name contains the user's display name after login } catch (error) { console.error(`Login failed: ${error.message}`); // Possible errors: // - "Cannot Login: email password combination not existing" // - Network errors } return bring; } ``` -------------------------------- ### Load Item Translations (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Loads item name translations for a specific locale, enabling display of items in the user's preferred language. Requires prior authentication. ```javascript const bring = await authenticate(); try { const translations = await bring.loadTranslations('de-DE'); // translations = { // 'Milk': 'Milch', // 'Bread': 'Brot', // 'Eggs': 'Eier', // ... // } const itemName = 'Milk'; const localizedName = translations[itemName] || itemName; console.log(`${itemName} in German: ${localizedName}`); } catch (error) { console.error(`Failed to load translations: ${error.message}`); } ``` -------------------------------- ### loadTranslations(locale) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Loads item name translations for a specific locale. This is useful for displaying items in the user's preferred language. ```APIDOC ## POST /translations ### Description Loads item name translations for a specific locale. ### Method POST ### Endpoint /translations ### Parameters #### Query Parameters - **locale** (string) - Required - The locale for which to load translations (e.g., 'de-DE'). ### Request Example ```json { "locale": "de-DE" } ``` ### Response #### Success Response (200) - **translations** (object) - An object where keys are original item names and values are their translated names. #### Response Example ```json { "translations": { "Milk": "Milch", "Bread": "Brot", "Eggs": "Eier" } } ``` ``` -------------------------------- ### Retrieve Items from a Shopping List using JavaScript Source: https://context7.com/foxriver76/node-bring-api/llms.txt Retrieves all items from a specific shopping list, identified by its UUID. Returns both current purchase items and recently purchased items. This function requires an authenticated 'bring' instance and a valid listUuid. ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { const items = await bring.getItems(listUuid); // items = { // uuid: '9b3ba561-02ad-4744-a737-c43k7e5b93ec', // status: 'REGISTERED', // purchase: [ // { name: 'Milk', specification: '2 liters' }, // { name: 'Bread', specification: 'whole wheat' } // ], // recently: [ // { name: 'Eggs', specification: '12 pack' } // ] // } console.log('Items to buy:'); items.purchase.forEach(item => { console.log(`- ${item.name}: ${item.specification}`); }); console.log(' Recently purchased:'); items.recently.forEach(item => { console.log(`- ${item.name}: ${item.specification}`); }); } catch (error) { console.error(`Failed to get items: ${error.message}`); } ``` -------------------------------- ### Attach Image to Item (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Attaches an image to a specific item in a shopping list. The image must be provided as a base64 encoded string. This function requires an authenticated Bring! client and the item's UUID. It returns the URL of the saved image. ```javascript const bring = await authenticate(); const itemUuid = 'item-uuid-123'; try { const result = await bring.saveItemImage(itemUuid, { imageData: 'base64-encoded-image-string...' }); // result = { imageUrl: 'https://api.getbring.com/images/...' } console.log(`Image saved: ${result.imageUrl}`); } catch (error) { console.error(`Failed to save image: ${error.message}`); } ``` -------------------------------- ### Add Item to Shopping List (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Adds a new item to a specified shopping list. An optional specification or description can be included. The function requires an authenticated Bring! client, the list UUID, and the item name. It returns an empty string upon successful addition (HTTP 204). ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { // Add item with specification await bring.saveItem(listUuid, 'Milk', '2% organic, 1 gallon'); console.log('Added: Milk (2% organic, 1 gallon)'); // Add item without specification await bring.saveItem(listUuid, 'Bananas', ''); console.log('Added: Bananas'); // Returns empty string on success (HTTP 204) } catch (error) { console.error(`Failed to save item: ${error.message}`); } ``` -------------------------------- ### Move Item to Recent List (Mark as Bought) (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Moves an item from the active shopping list to the recently purchased list, effectively marking it as bought. It requires an authenticated Bring! client, the list UUID, and the item name. Success is indicated by an empty string response (HTTP 204). ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { await bring.moveToRecentList(listUuid, 'Milk'); console.log('Marked as purchased: Milk'); // Returns empty string on success (HTTP 204) } catch (error) { console.error(`Failed to move item: ${error.message}`); } ``` -------------------------------- ### Remove Image from Item (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Removes an image previously attached to a specific item. This operation requires an authenticated Bring! client and the item's UUID. A successful removal is indicated by an empty string response (HTTP 204). ```javascript const bring = await authenticate(); const itemUuid = 'item-uuid-123'; try { await bring.removeItemImage(itemUuid); console.log('Image removed'); // Returns empty string on success (HTTP 204) } catch (error) { console.error(`Failed to remove image: ${error.message}`); } ``` -------------------------------- ### Remove Item from Shopping List (JavaScript) Source: https://context7.com/foxriver76/node-bring-api/llms.txt Completely removes a specified item from a shopping list. This function requires an authenticated Bring! client, the list UUID, and the name of the item to be removed. It returns an empty string on success (HTTP 204). ```javascript const bring = await authenticate(); const listUuid = '9b3ba561-02ad-4744-a737-c43k7e5b93ec'; try { await bring.removeItem(listUuid, 'Milk'); console.log('Removed: Milk'); // Returns empty string on success (HTTP 204) } catch (error) { console.error(`Failed to remove item: ${error.message}`); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.