> ## Documentation Index
> Fetch the complete documentation index at: https://doc.qbilon.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Plain Text Data

> Format plain-text data for exchange with Qbilon.

## Preface

Qbilon provides a simple API that allows users to store and retrieve plain text data for input or output purposes.

This plain text data is typically used in two contexts:

* reading the content of a file that was uploaded through a file configuration parameter of that task or
* creating an output that can be used by other tasks or by the same task as input later on.

## Endpoints

A task that wants to create, read, or delete plain text data can interact with three endpoints:

* Create/Replace: `POST https://host/apiv1/data/blob/:taskId/:name`
* Read: `GET https://host/apiv1/data/blob/:taskId/:name`
* Delete: `DELETE https://host/apiv1/data/blob/:taskId/:name`

The `host` part is the domain of your Qbilon instance. The `taskId` is the numeric ID of your task and can be retrieved via the environment variables of your custom task (see [Custom Task](https://doc.qbilon.io/12-customizing-qbilon/custom-tasks/index)). The `name` is the file name and is usually defined by a configuration parameter or freely by the author of a custom task.

### Creating Data

To create text data from a custom task, simply make a call to the endpoint mentioned below. To make a successful call, adhere to the following:

* **Endpoint**: `POST https://<host>/apiv1/data/blob/<taskId>/<name>`
* **Authentication**: For authentication, you can use either Basic Authentication or a Bearer Authentication Token, which is provided by the environment variables to your task, see [Custom Task](https://doc.qbilon.io/12-customizing-qbilon/custom-tasks/index).
* **Content-Type Header**: use `text/plain`
* **Filename**: may have a maximum of 255 characters
* **TaskId**: must be an existing task ID
* **Content Size**: should be a maximum of 10 MB.

The following code snippet depicts a simple example of what a custom task might look like in code:

```javascript theme={null}
import fetch from 'node-fetch';
import { readFileSync } from 'fs';

const token = readFileSync('/tmp/task-authentication');
const auth = `Bearer ${token}`;
const host = process.env.QB_HOST;
const id = process.env.QB_TASK_ID;

async function storeBlob(text) {
  await fetch(`${host}/apiv1/data/blob/${id}/mydata`, {
        method: 'POST',
        headers: {
          'Authorization': auth,
          'Content-Type': 'text/plain'
        },
        body: text
    });
}

storeBlob("Some random text that could be anything, e.g., xml, json, plain text, etc.");
```

### Reading Data

To read text data from a custom task in Qbilon, you only need to call the endpoint mentioned below. To make a successful call, adhere to the following:

* **Endpoint**: `GET https://<host>/apiv1/data/blob/<taskId>/<name>`
* **Authentication**: For authentication, you can use either Basic Authentication or a Bearer Authentication Token, which is provided by environment variables to your task, see [Custom Task](https://doc.qbilon.io/12-customizing-qbilon/custom-tasks/index).
* **Filename**: may be a maximum of 255 characters long and must have been written beforehand
* **TaskId**: must be an existing task ID

The following code snippet depicts a simple example of what a custom task might look like in code:

```javascript theme={null}
import fetch from 'node-fetch';
import { readFileSync } from 'fs';

const token = readFileSync('/tmp/task-authentication');
const auth = `Bearer ${token}`;
const host = process.env.QB_HOST;
const id = process.env.QB_TASK_ID;

async function readBlob(name) {
  const blobResponse = await fetch(`${host}/apiv1/data/blob/${id}/${name}`, {
      method: 'GET',
      headers: {
        'Authorization': auth
      }
  });
  const blobData = await blobResponse.text();
  return blobData;
}

readBlob("mydata");
```

### Deleting Data

To delete text data from a custom task in Qbilon, you only need to make a call to the endpoint mentioned below. To make a successful call, adhere to the following:

* **Endpoint**: `DELETE https://<host>/apiv1/data/blob/<taskId>/<name>`
* **Authentication**: For authentication, you can use either Basic Authentication or a Bearer Authentication Token, which is provided by the environment variables to your task, see [Custom Task](https://doc.qbilon.io/12-customizing-qbilon/custom-tasks/index).
* **Filename**: it may have at max 255 chars and must be one that was written beforehand
* **TaskId**: must be an existing task ID

The following code snippet depicts a simple example of what a custom task might look like in code:

```javascript theme={null}
import fetch from 'node-fetch';
import { readFileSync } from 'fs';

const token = readFileSync('/tmp/task-authentication');
const auth = `Bearer ${token}`;
const host = process.env.QB_HOST;
const id = process.env.QB_TASK_ID;

async function deleteBlob(name) {
  await fetch(`${host}/apiv1/data/blob/${id}/${name}`, {
        method: 'DELETE',
        headers: {
          'Authorization': auth
        }
    });
}

deleteBlob("mydata");
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.