You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The official Javascript package for the [Patch API](https://www.usepatch.com)
6
7
7
8
## Documentation
9
+
8
10
For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml)
9
11
10
12
## Installation
11
13
12
14
### NPM
15
+
13
16
```shell
14
17
npm install @patch-technology/patch --save
15
18
```
16
19
17
20
### Yarn
21
+
18
22
```shell
19
23
yarn add @patch-technology/patch
20
24
```
21
25
22
26
### Requirements
23
-
* Node 10 +
27
+
28
+
- Node 10 +
24
29
25
30
## Usage
26
31
27
32
### Configuration
28
33
29
34
After installing the package, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:
35
+
30
36
```javascript
31
37
// ES6+
32
-
importPatchfrom'@patch-technology/patch'
33
-
constpatch=Patch('key_test_1234')
38
+
importPatchfrom"@patch-technology/patch";
39
+
constpatch=Patch("key_test_1234");
34
40
35
41
// ES5
36
-
var patch =require('@patch-technology/patch')('key_test_1234')
42
+
var patch =require("@patch-technology/patch")("key_test_1234");
37
43
```
38
44
39
45
### Orders
46
+
40
47
In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.
Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.
constmass=1000000// Pass in the mass in grams (i.e. 1 metric tonne)
76
-
patch.estimates.createMassEstimate({ mass_g: mass })
85
+
constmass=1000000;// Pass in the mass in grams (i.e. 1 metric tonne)
86
+
patch.estimates.createMassEstimate({ mass_g: mass });
77
87
78
88
// Retrieve an estimate
79
-
constestimateId='est_test_1234'
80
-
patch.estimates.retrieveEstimate(estimate_id)
89
+
constestimateId="est_test_1234";
90
+
patch.estimates.retrieveEstimate(estimate_id);
81
91
82
92
// Retrieve a list of estimates
83
-
constpage=1// Pass in which page of estimates you'd like
84
-
patch.estimates.retrieveEstimates({ page })
93
+
constpage=1;// Pass in which page of estimates you'd like
94
+
patch.estimates.retrieveEstimates({ page });
85
95
```
86
96
87
97
### Projects
98
+
88
99
Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.
constproject_id='pro_test_1234'// Pass in the project's ID
96
-
patch.projects.retrieveProject(project_id)
107
+
constproject_id="pro_test_1234";// Pass in the project's ID
108
+
patch.projects.retrieveProject(project_id);
97
109
98
110
// Retrieve a list of projects
99
-
constpage=1// Pass in which page of projects you'd like
100
-
patch.projects.retrieve_projects({ page })
111
+
constpage=1;// Pass in which page of projects you'd like
112
+
patch.projects.retrieve_projects({ page });
101
113
```
102
114
103
115
### Preferences
116
+
104
117
Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.usepatch.com/projects).
0 commit comments