# Call an API or run code

> Reach any service with a REST or GraphQL API, or compute something no built-in step covers. Use them when nothing else fits.

Web page: https://docs.lodol.com/docs/guides/http-and-code

Two built-in steps can do almost anything: **Call an API** reaches any web API, and **Run Python code** runs a short script. Every other step shows its app and labeled fields, which anyone on your team can read and change. These two show a URL and headers, or a block of code. Reach for them when no app action or built-in step does the job.

## Call an API

**Call an API** calls a REST or GraphQL endpoint that Lodol has no app for, and hands the response to later steps.

| Field | What it's for |
| --- | --- |
| **URL** | The full address, starting with `https://`. It can include workspace values, such as `@values.BASE_URL` followed by a path. |
| **Method** | `GET` unless you choose another |
| **Headers** | Such as an `Authorization` header, using a [secret](https://docs.lodol.com/docs/concepts/connections.md#secrets) for the token |
| **Query parameters** | Added to the end of the URL |
| **Body** | What to send, as JSON or a value from an earlier step. GraphQL queries go here too. |
| **Body format** | `json` (the default), `form`, `text` or `none` |
| **Response format** | `auto` (the default) follows the response's content type, so JSON becomes an object and a download becomes a file |
| **If the call fails** | Fail the run (the default), or continue so later steps can check the status |

The step returns the response's `status`, `ok` (true for a success status), `headers`, `body` and `url`.

<Callout type="warn" title="Only for services Lodol doesn't connect to">
  A Call an API step can't use an app's connection; it only has the secrets you give it. Calling Google's or Slack's API with it goes out without your account. For any app in the [directory](https://docs.lodol.com/docs/integrations.md), use its actions.
</Callout>

## Run Python code

**Run Python code** runs a short script, for the rare reshaping or calculation no built-in step covers.

- **Inputs** maps names to values from earlier steps; the script reads them by those names.
- The script's result is whatever it assigns to a variable named `output`.
- **Output type** checks the result before later steps use it: `auto` (the default), `text`, `number`, `boolean`, `list` or `object`.

```python title="Python code: check an IBAN"
# Inputs: iban (text). Output type: boolean.
iban = iban.replace(" ", "").upper()
rearranged = iban[4:] + iban[:4]
digits = "".join(str(int(char, 36)) for char in rearranged)
output = int(digits) % 97 == 1
```

The script runs in a secure sandbox with limits on time and memory. It has no internet or file access: use Call an API or an app's action to reach a service, and [Read a file](https://docs.lodol.com/docs/integrations/built-in/files.md#read-a-file) to get what's inside a file.

Before writing code, check the built-in steps: most text, list, number and date work, such as grouping records by a field, totalling a column or formatting a date, already has a step.

## Reference

Every field is on the [HTTP](https://docs.lodol.com/docs/integrations/built-in/http.md) and [Code](https://docs.lodol.com/docs/integrations/built-in/code.md) reference pages.
