### Install Patch SDK via NPM Source: https://github.com/patch-technology/patch-node/blob/main/README.md Install the Patch SDK using npm. Ensure you have Node.js 10+ installed. ```shell npm install @patch-technology/patch --save ``` -------------------------------- ### Install Patch SDK via Yarn Source: https://github.com/patch-technology/patch-node/blob/main/README.md Install the Patch SDK using Yarn. Ensure you have Node.js 10+ installed. ```shell yarn add @patch-technology/patch ``` -------------------------------- ### Set Test API Key Source: https://github.com/patch-technology/patch-node/blob/main/README.md Before running tests, set the SANDBOX_API_KEY environment variable. Use test API keys that typically start with 'key_test_'. ```sh $ export SANDBOX_API_KEY= ``` -------------------------------- ### Initialize Patch Client and Retrieve Projects Source: https://github.com/patch-technology/patch-node/blob/main/README.md Open a Node.js REPL, import the Patch package, initialize the client with an API key, and retrieve projects. Ensure the SANDBOX_API_KEY environment variable is set. ```javascript const Patch = require('@patch-technology/patch'); const patch = Patch.default(process.env.SANDBOX_API_KEY); patch.projects.retrieveProjects().then((response) => console.log(response)); ``` -------------------------------- ### Build Patch Node SDK Source: https://github.com/patch-technology/patch-node/blob/main/README.md Run this command to compile the SDK and generate the 'dist' folder with compiled code. ```sh $ npm run build ``` -------------------------------- ### Run Patch Node SDK Tests Source: https://github.com/patch-technology/patch-node/blob/main/README.md After setting the API key and ensuring you are in the root 'patch-node' directory, run this command to execute the package's test suite. ```sh $ npm run test ``` -------------------------------- ### Create Order with Total Price and Currency Source: https://github.com/patch-technology/patch-node/blob/main/README.md Create a Patch order by specifying the total price in the smallest currency unit (e.g., cents for USD). ```javascript // Create an order with total price const totalPrice = 500; // Pass in the total price in smallest currency unit (ie cents for USD). const currency = 'USD'; patch.orders.createOrder({ total_price: totalPrice, currency: currency }); ``` -------------------------------- ### Configure Patch SDK with API Key Source: https://github.com/patch-technology/patch-node/blob/main/README.md Initialize the Patch SDK with your API key. Supports both ES6+ and ES5 import/require syntax. ```javascript // ES6+ import Patch from '@patch-technology/patch'; const patch = Patch('key_test_1234'); ``` ```javascript // ES5 var patch = require('@patch-technology/patch').default('key_test_1234'); ``` -------------------------------- ### Place a Patch Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Initiate the placement of a Patch order using its ID. ```javascript // Place an order const orderId = 'ord_test_1234'; // Pass in the order's id patch.orders.placeOrder(orderId); ``` -------------------------------- ### Create Order with Amount and Unit Source: https://github.com/patch-technology/patch-node/blob/main/README.md Create a Patch order by specifying the amount and its unit (e.g., grams). ```javascript // Create order with amount const amount = 1_000_000; // Pass in the amount in unit specified const unit = 'g'; patch.orders.createOrder({ amount: amount, unit: unit }); ``` -------------------------------- ### Retrieve a List of Projects Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a paginated list of Patch projects. Specify the desired page number. ```javascript // Retrieve a list of projects const page = 1; // Pass in which page of projects you'd like patch.projects.retrieveProjects({ page }); ``` -------------------------------- ### Create Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Creates an order. You can specify either amount and unit, or total_price and currency. The issued_to field is optional. ```APIDOC ## Create Order ### Description Creates an order. You can specify either amount and unit, or total_price and currency. The issued_to field is optional. ### Method `patch.orders.createOrder(options)` ### Parameters #### Request Body - **amount** (number) - Required (if total_price is not provided) - The amount in the specified unit. - **unit** (string) - Required (if total_price is not provided) - The unit of the amount (e.g., 'g'). - **total_price** (number) - Required (if amount is not provided) - The total price in the smallest currency unit (e.g., cents for USD). - **currency** (string) - Required (if amount is not provided) - The currency of the total price (e.g., 'USD'). - **issued_to** (object) - Optional - Information about the recipient of the order. - **email** (string) - The email address of the recipient. - **name** (string) - The name of the recipient. ### Request Example ```javascript // Create order with amount const amount = 1_000_000; const unit = 'g'; patch.orders.createOrder({ amount: amount, unit: unit }); // Create an order with total price const totalPrice = 500; const currency = 'USD'; patch.orders.createOrder({ total_price: totalPrice, currency: currency }); // Create order with the issued_to field const amount = 1_000_000; const unit = 'g'; const issued_to = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.createOrder({ amount: amount, unit: unit, issued_to: issued_to }); ``` ``` -------------------------------- ### Create Order with Issued To Information Source: https://github.com/patch-technology/patch-node/blob/main/README.md Create a Patch order, optionally including details about the recipient like email and name. ```javascript // Create order with the issued_to field (optional) const amount = 1_000_000; // Pass in the amount in unit specified const unit = 'g'; const issued_to = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.createOrder({ amount: amount, unit: unit, issued_to: issued_to }); ``` -------------------------------- ### Link Local Patch Node Package Source: https://github.com/patch-technology/patch-node/blob/main/README.md After building, link the package locally to use it in other projects. Navigate to your project folder and run the link command. ```sh $ npm link ``` -------------------------------- ### Retrieve Project in Another Language Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a specific project's details in a different language by specifying the 'acceptLanguage' option. ```javascript // Retrieve a project in another language // See http://docs.patch.test:3000/#/internationalization for more information and support languages const projectId = 'pro_test_1234'; patch.projects.retrieveProject(projectId, { acceptLanguage: 'fr' }); ``` -------------------------------- ### Place Order with Issued To Information Source: https://github.com/patch-technology/patch-node/blob/main/README.md Place a Patch order, optionally specifying recipient details. ```javascript // Place an order with the issued_to field (optional) const orderId = 'ord_test_1234'; // Pass in the order's id const issued_to = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.placeOrder(orderId, { issued_to: issued_to }); ``` -------------------------------- ### Retrieve Projects Filtered by Minimum Available Mass Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a list of Patch projects that have a minimum available mass of CO2 removal. ```javascript // Retrieve a filtered list of projects const minimumAvailableMass = 100; // Pass in the minimum available inventory the projects should have patch.projects.retrieveProjects({ minimumAvailableMass }); ``` -------------------------------- ### Retrieve Projects Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieves a list of projects, with optional filtering and pagination. Filters include country, type, and minimumAvailableMass. Supports acceptLanguage. ```APIDOC ## Retrieve Projects ### Description Retrieves a list of projects, with optional filtering and pagination. Filters include country, type, and minimumAvailableMass. Supports acceptLanguage. ### Method `patch.projects.retrieveProjects(options)` ### Parameters #### Query Parameters - **page** (number) - Optional - The page number of projects to retrieve. - **country** (string) - Optional - Filters projects by country. - **type** (string) - Optional - Filters projects by type (e.g., 'biomass'). - **minimumAvailableMass** (number) - Optional - Filters projects by minimum available mass. - **acceptLanguage** (string) - Optional - The preferred language for the project details (e.g., 'fr'). ### Request Example ```javascript // Retrieve a list of projects const page = 1; patch.projects.retrieveProjects({ page }); // Retrieve a filtered list of projects by country const country = 'CA'; patch.projects.retrieveProjects({ country }); // Retrieve a filtered list of projects by type const type = 'biomass'; patch.projects.retrieveProjects({ type }); // Retrieve a filtered list of projects by minimum available mass const minimumAvailableMass = 100; patch.projects.retrieveProjects({ minimumAvailableMass }); ``` ``` -------------------------------- ### Retrieve Project Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieves a specific project by its ID. Supports specifying acceptLanguage for internationalization. ```APIDOC ## Retrieve Project ### Description Retrieves a specific project by its ID. Supports specifying acceptLanguage for internationalization. ### Method `patch.projects.retrieveProject(projectId, options)` ### Parameters #### Path Parameters - **projectId** (string) - Required - The ID of the project to retrieve. #### Query Parameters - **acceptLanguage** (string) - Optional - The preferred language for the project details (e.g., 'fr'). ### Request Example ```javascript const projectId = 'pro_test_1234'; patch.projects.retrieveProject(projectId); // Retrieve a project in another language const projectId = 'pro_test_1234'; patch.projects.retrieveProject(projectId, { acceptLanguage: 'fr' }); ``` ``` -------------------------------- ### Place Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Places an order, making it active. The issued_to field can be optionally provided. ```APIDOC ## Place Order ### Description Places an order, making it active. The issued_to field can be optionally provided. ### Method `patch.orders.placeOrder(orderId, options)` ### Parameters #### Path Parameters - **orderId** (string) - Required - The ID of the order to place. #### Request Body - **issued_to** (object) - Optional - Information about the recipient of the order. - **email** (string) - The email address of the recipient. - **name** (string) - The name of the recipient. ### Request Example ```javascript // Place an order const orderId = 'ord_test_1234'; patch.orders.placeOrder(orderId); // Place an order with the issued_to field const orderId = 'ord_test_1234'; const issued_to = { email: 'issuee@companya.com', name: 'Olivia Jones' }; patch.orders.placeOrder(orderId, { issued_to: issued_to }); ``` ``` -------------------------------- ### Retrieve a List of Orders Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a paginated list of Patch orders. Specify the desired page number. ```javascript // Retrieve a list of orders const page = 1; // Pass in which page of orders you'd like patch.orders.retrieveOrders({ page }); ``` -------------------------------- ### Link Patch Node in Test Project Source: https://github.com/patch-technology/patch-node/blob/main/README.md In a separate test project, link the locally built package to use it. This creates a symlink in the 'node_modules' directory. ```sh $ npm link @patch-technology/patch ``` -------------------------------- ### Retrieve Projects Filtered by Type Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a list of Patch projects filtered by a specific project type (e.g., 'biomass'). ```javascript // Retrieve a filtered list of projects const type = 'biomass'; // Pass in the project type you'd like to filter by patch.projects.retrieveProjects({ type }); ``` -------------------------------- ### Retrieve a Specific Project Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve details of a specific Patch project using its ID. ```javascript // Retrieve a project const projectId = 'pro_test_1234'; // Pass in the project's ID patch.projects.retrieveProject(projectId); ``` -------------------------------- ### Retrieve Projects Filtered by Country Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve a list of Patch projects filtered by a specific country code. ```javascript // Retrieve a filtered list of projects const country = 'CA'; // Pass in the country you'd like to get projects from patch.projects.retrieveProjects({ country }); ``` -------------------------------- ### Retrieve a Specific Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieve details of a specific Patch order using its ID. ```javascript // Retrieve an order orderId = 'ord_test_1234'; // Pass in the order's id patch.orders.retrieveOrder(orderId); ``` -------------------------------- ### Retrieve Orders Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieves a list of orders, with optional pagination. ```APIDOC ## Retrieve Orders ### Description Retrieves a list of orders, with optional pagination. ### Method `patch.orders.retrieveOrders(options)` ### Parameters #### Query Parameters - **page** (number) - Optional - The page number of orders to retrieve. ### Request Example ```javascript const page = 1; patch.orders.retrieveOrders({ page }); ``` ``` -------------------------------- ### Retrieve Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Retrieves a specific order by its ID. ```APIDOC ## Retrieve Order ### Description Retrieves a specific order by its ID. ### Method `patch.orders.retrieveOrder(orderId)` ### Parameters #### Path Parameters - **orderId** (string) - Required - The ID of the order to retrieve. ### Request Example ```javascript const orderId = 'ord_test_1234'; patch.orders.retrieveOrder(orderId); ``` ``` -------------------------------- ### Cancel a Patch Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Cancel a specific Patch order using its ID. ```javascript // Cancel an order const orderId = 'ord_test_1234'; // Pass in the order's id patch.orders.cancelOrder(orderId); ``` -------------------------------- ### Cancel Order Source: https://github.com/patch-technology/patch-node/blob/main/README.md Cancels an order. ```APIDOC ## Cancel Order ### Description Cancels an order. ### Method `patch.orders.cancelOrder(orderId)` ### Parameters #### Path Parameters - **orderId** (string) - Required - The ID of the order to cancel. ### Request Example ```javascript const orderId = 'ord_test_1234'; patch.orders.cancelOrder(orderId); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.