# API-Auth Examples

**The main goal of these examples is to demonstrate how a** [**Task Developer**](/overview/how-do-you-intend-to-use-truebit.md#task-developers) **can create** [**Truebit API Tasks**](/developing-truebit-tasks/how-to-create-api-tasks.md) **that interact with authenticated endpoints.**

\
In this section, we’ll walk through how to handle each of the supported authentication methods: *custom-header, basic-auth*, and aws-signature.

### 1. Test Your Manifest

Use the  [`start-api`](/developing-truebit-tasks/truebit-cli-reference.md#start-api) command to execute the API task locally within the context of the Truebit Node. This allows you to verify that the authenticated endpoints behave as expected.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/custom-header/custom-header.manifest.json api-auth/custom-header/custom-header.input.json custom-header 'username:foo, password:bar'
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/basic-auth/basic-auth.manifest.json api-auth/basic-auth/basic-auth.input.json basic-auth 'username:<username>,password:<password>'
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit start-api api-auth/aws-signature/aws-signature.manifest.json api-auth/aws-signature/aws-signature.input.json aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"
```

{% endcode %}

### 2. Create The Truebit API Task

Once the authenticated endpoints have been successfully tested, create the Truebit API Task by running the [`create-api`](/developing-truebit-tasks/truebit-cli-reference.md#create-api) command.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/custom-header/custom-header.manifest.json
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/basic-auth/basic-auth.manifest.json
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit create-api api-auth/aws-signature/aws-signature.manifest.json
```

{% endcode %}

### 3. Deploy the Truebit API Task

Deploy the created API Task using the [deploy](/developing-truebit-tasks/truebit-cli-reference.md#deploy) command. This makes it available for execution by [Task Requesters](/overview/how-do-you-intend-to-use-truebit.md#task-requesters).

{% code overflow="wrap" %}

```bash
truebit deploy <namespace> <taskname> --taskId <taskId>
```

{% endcode %}

* \[taskId]: Add the taskId generated in step 2

### 4. Deploy the Authentication Credentials

After deploying the API Task, upload the required authentication credentials using the `api-auth` command. This ensures the Task Requester can execute the task without encountering authentication issues.

#### custom-header

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> custom-header "username:<username>,password:<password>"
```

{% endcode %}

**basic-auth**

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> basic-auth 'username:<username>,password:<password>'
```

{% endcode %}

**aws-signature**

{% code overflow="wrap" %}

```bash
truebit api-auth <namespace> <taskname> <taskId> aws-signature "accessKey:AKIA2VXUSRQO3CTJ5UH5,secretKey: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"
```

{% endcode %}

### 5. Execute The Truebit API Task

Now, you're ready to execute the Truebit API Task using the [execute-by-name](/integrating-truebit-tasks/api-task-execution/execute-api-tasks.md) endpoint and retrieve the Truebit transcript.


---

# 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://devs.truebit.io/developing-truebit-tasks/how-to-create-api-tasks/api-task-examples/api-auth-examples.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.
