@@ -72,6 +72,14 @@ $client = new \GuzzleHttp\Client([
72
72
]);
73
73
```
74
74
75
+ ``` javascript [activate:NodeJS]
76
+
77
+ // Install the node-fetch library by following the official documentation:
78
+ // https://www.npmjs.com/package/node-fetch
79
+
80
+ import fetch from ' node-fetch' ;
81
+ ```
82
+
75
83
### 1. Get the PIM structure by fetching a channel from API
76
84
77
85
Workflow
@@ -96,6 +104,24 @@ $response = $client->get(
96
104
$channel = json_decode($response->getBody()->getContents(), true);
97
105
```
98
106
107
+ ``` javascript [activate:NodeJS]
108
+
109
+ import fetch from ' node-fetch' ;
110
+
111
+ const pimUrl = ' https://url-of-your-pim.com' ;
112
+ const accessToken = ' your_app_token' ; // Token provided during oAuth steps
113
+
114
+ const channelCode = ' ecommerce' ;
115
+
116
+ const response = await fetch (` ${ pimUrl} /api/rest/v1/channels/${ channelCode} ` , {
117
+ headers: {
118
+ ' Authorization' : ` Bearer ${ accessToken} `
119
+ }
120
+ });
121
+
122
+ const channel = await response .json ();
123
+ ```
124
+
99
125
The retrieved channel resource looks like this:
100
126
101
127
``` php [activate:PHP]
@@ -124,6 +150,32 @@ var_export($channel);
124
150
]
125
151
```
126
152
153
+ ``` javascript [activate:NodeJS]
154
+
155
+ console .log (channel);
156
+
157
+ // Output
158
+ {
159
+ code: ' ecommerce' ,
160
+ currencies: [
161
+ ' USD' ,
162
+ ' EUR'
163
+ ],
164
+ locales: [
165
+ ' de_DE' ,
166
+ ' en_US' ,
167
+ ' fr_FR'
168
+ ],
169
+ category_tree: ' master' ,
170
+ conversion_units: {},
171
+ labels: {
172
+ en_US: ' Ecommerce' ,
173
+ de_DE: ' Ecommerce' ,
174
+ fr_FR: ' Ecommerce'
175
+ }
176
+ }
177
+ ````
178
+
127
179
### 2. Store the PIM structure
128
180
129
181
We advise storing in your App locales, currencies, and root category.
@@ -137,3 +189,10 @@ storeCurrencies($channel['currencies']);
137
189
storeLocales($channel['locales']);
138
190
storeCategoryTree($channel['category_tree']);
139
191
` ` `
192
+
193
+ ` ` ` javascript [activate:NodeJS]
194
+
195
+ storeCurrencies(channel.currencies);
196
+ storeLocales(channel.locales);
197
+ storeCategoryTree(channel.category_tree);
198
+ ` ` `
0 commit comments