# 2. Fetch Applications, Data Plugs and Data Debits

### Applications

#### Get all the apps

The are 2 ways to fetch applications:

1. With default options.

**Example:**

```typescript
try {
    const result = await hat.applications().getAllDefault();

    if (result.parsedBody) {
        // result.parsedBody contains an array of Applications.
    }
} catch (error) {
    // The request failed...
}
```

2\. With custom options.

**Example:**

```typescript
// In custom options you can specify the following parameters: "ordering", "orderBy", "take", "skip"

const options = {
    ordering: "descending",
    orderBy: "name"
};

try {
    const result = await hat.applications().getAll(options);

    if (result.parsedBody) {
        // result.parsedBody contains an array of Applications.
    }
} catch (error) {
    // The request failed...
}
```

#### Get an application with a specific ID

**Example:**

```typescript
try {
    const result = await hat.applications().getById("testhatapp");

    if (result.parsedBody) {
        // result.parsedBody contains the application.
    }
} catch (error) {
    // The request failed...
}
```

#### Get an application status

| Parameters  | Type                                                                                                        |
| ----------- | ----------------------------------------------------------------------------------------------------------- |
| application | [HatApplication](https://docs.dataswift.io/guides/application-management/01-application-information-format) |

**Example:**

```typescript
const status = hat.applications().getAppStatus(application);

console.log(status);
// Will print one of  'goto' | 'running' | 'fetching' | 'failing' | 'untouched' | 'update';
```

#### Generate a Data Plug setup URL

You can generate a URL to redirect the user to setup a Data Plug.

| Parameters  | Type                                                                                                        |
| ----------- | ----------------------------------------------------------------------------------------------------------- |
| application | [HatApplication](https://docs.dataswift.io/guides/application-management/01-application-information-format) |
| redirect    | string                                                                                                      |
| fallback    | string                                                                                                      |

**Example:**

```typescript
const redirectUrl = "https://myapp.dataswift.io/app/redirect";
const fallbackUrl = "https://myapp.dataswift.io/app/fallback";
const generatedUrl = hat.applications().getSetupUrl(application, redirectUrl, fallbackUrl);

console.log(generatedUrl); 
// Will print: https://testing.hubat.net/#/hatlogin?name=facebook&fallback=https://myapp.dataswift.io/app/fallback&redirect=https://facebook.hubofallthings.com%3Fredirect=https://myapp.dataswift.io/app/redirect

window.location.href = generatedUrl; // Navigate the user to setup the Data Plug.
```


---

# 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://docs.dataswyft.com/build/advanced-topics/pda-authentication/password-management/tutorials/data-api/2.-fetch-applications-data-plugs-and-data-debits.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.
