# Work in Progress: How to Ping an API

{% hint style="info" %}
This can be done in a Computed Field if you want to fetch from the API when the Flow gets loaded or you can do it as an Action if you want to trigger the fetch at some specific point or points of the Flow.
{% endhint %}

## As a Computed Field:

1. Create a Computed Field (learn how to in the "[<mark style="color:blue;">**How to Create Computed Fields**</mark>](/other-useful-docs/work-in-progress/pending/work-in-progress-how-to-create-computed-fields.md)" doc).
2. Write your code. It should look something like this:

```
return fetch('https://example.com/api', {
  method: 'POST', // or 'GET'
  headers: {
    'Content-Type': 'application/json' // Common example of a header
  },
  body: JSON.stringify({ key: 'value' }), // For sending some data
})
  .then(response => response.json()) // This just turns the response into JSON data
  .then(data => { /* Do something with data */ })
```

## As an Action:

### Step 1: Create the Data Output

* Go to the "All" Tab on the Left Sidebar
* Scroll to the bottom where you can find the Data Outputs area, and click on "Create New"
* On the Options Tab of the Right Sidebar select "Custom" as an output
* Check the "Manual Trigger Only" box

### Step 2: Write your Code

* Click on "Generate Sample Code" below the code editor, on the Options Tab of the Right Sidebar
* Write your code inside the created function. It should look something like this:

```
fetch('https://example.com/api', { 
  method: 'POST', // or 'GET'
  headers: {
    'Content-Type': 'application/json' // Common example of a header
  },
  body: JSON.stringify({ key: 'value' }), // For sending some data
})
  .then(response => response.json()) // This just turns the response into JSON data
  .then(data => { /* Do something with data */ })
```

### Step 3: Trigger it!

* Select the page or component where you want to ping the API&#x20;
* Go to the Triggers Tab on the Right Sidebar
* Choose to trigger on page load, on page complete, on click, on success, etc.
* Select the Data Output you want to trigger
* Done!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.trysavvy.com/other-useful-docs/work-in-progress/pending/work-in-progress-how-to-ping-an-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
