> 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="/files/cp6wG8VDPI4xlFNyb9K5" 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
