Skip to content

Commit cdd18ce

Browse files
authored
[excel] (External Calls) Adding fetch post sample (#604)
* Adding post sample * Fix grammar and spacing
1 parent d4a127f commit cdd18ce

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/develop/use-json.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ interface Transaction {
203203
204204
:::image type="content" source="../images/create-json-console-output.png" alt-text="The console output from the previous script that shows the property values of the object.":::
205205
206+
### Export JSON with `fetch`
207+
208+
Much like importing data with `fetch`, you can send data from your workbook with a similar command. A `POST` command takes any stringified JSON data and sends it to the specified endpoint.
209+
210+
To see this in action, replace the `console.log(transactions);` line in the previous sample with the following code. This issues a `POST` command to a testing server, then reads the data back.
211+
212+
```typescript
213+
const response = await fetch('https://jsonplaceholder.typicode.com/posts', {
214+
method: 'POST',
215+
body: JSON.stringify(transactions),
216+
headers: {
217+
'Content-type': 'application/json; charset=UTF-8',
218+
},
219+
});
220+
const jsonData: object[] = await response.json();
221+
console.log(jsonData);
222+
```
223+
206224
### Use a generic object
207225
208226
The previous sample assumes the table header values are consistent. If your table has variable columns, you'll need to create a generic JSON object. The following script shows a script that logs any table as JSON.

0 commit comments

Comments
 (0)