> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/ubifunctions/advanced/raw-functions.md).

# Raw functions

For simplicity, default UbiFunctions do not let you use custom response codes or a `Content-Type` header other than `application/json`.

But what if your application needs this level of customization? This is why **Raw functions** exist. They let you:

* Capture the entire path inside the function, allowing you to use custom endpoint paths in addition to the UbiFunction’s native path. This lets you execute different routines based on the endpoint path.
* Receive and return custom headers. For example, `Authorization` headers.
* Set custom response codes such as 2xx, 4xx, and 5xx beyond the standard `200` in UbiFunctions. This lets the HTTP client know the exact result of the execution.
* Receive and return custom `Content-Type` headers for the request body and response, such as `application/json` or `text/plain`.

To enable **Raw functions**, toggle the option in the left-side settings section of the UbiFunction.

<figure><img src="https://884329393-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MhzNRg0B4ECiNXc093G%2Fuploads%2FQoejxSduVE2PfdIFFowB%2Fimage.png?alt=media&amp;token=a4357876-25fe-4d4c-9666-f6c9b660732a" alt=""><figcaption></figcaption></figure>

### args Object

Once enabled, the `args` object received in the UbiFunction’s main function follows this structure:

```
{
    "path": string,
    "headers": object, 
    "body": string,
}
```

Where:

| Key     | Type   | Description                                                 |
| ------- | ------ | ----------------------------------------------------------- |
| path    | string | UbiFunction path. For example: `/prv/<function-name>/`      |
| headers | object | Key-value object containing all the headers of the request. |
| body    | string | Body of the request                                         |

The base UbiFunction URL structure must remain intact. Otherwise, the request points to a different UbiFunction.

### Response codes

When a default UbiFunction finishes, it returns a `200` status code if everything goes well, or a `4xx` code if the execution fails. However, with Raw functions, you can customize the response code, body, and headers. This way, the HTTP client making the request knows the precise result of the execution.

Use the following JSON structure to customize the response:

```
{
 "status_code": int,
 "headers": object, 
 "body": string, 
}
```

Where:

| Key          | Type   | Description                                                                                                                             |
| ------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| status\_code | int    | Status codes to indicate whether the UbiFunction request has been successfully completed.                                               |
| headers      | object | <p>Key-value object containing headers of the response.<br><br><strong>Default value</strong>: {"Content-Type": "application/json"}</p> |
| body         | string | Formatted based on the Content-Type header.                                                                                             |

For more information, see:

{% embed url="<https://help.ubidots.com/en/articles/4936503-ubifunctions-using-raw-functions>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://dev.ubidots.com/ubifunctions/advanced/raw-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
