# API Client

The Swish API Client provides type-save methods for developers to interact with the API.&#x20;

{% hint style="warning" %}
When integrating Swish into a browser environment, using the [Browser library](/libraries/browser.md) is recommended.
{% endhint %}

## Requirements

This packages works in all JS environments were the [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is available.

## Installation

```sh
npm install @swishapp/api-client
```

## Usage

```typescript
import { createApiClient } from "@swishapp/api-client";

const swish = createApiClient({
  authToken: "your-api-auth-token"
});

const { data } = await swish.items.list();
```

## Reference

### Items

{% hint style="success" %}
For more details, refer to the [Items API reference](/swish-api/api-reference/items.md).
{% endhint %}

#### List all items

```typescript
const { data, error } = await swish.items.list();
```

#### List all items (pagination)

```typescript
const { data, error } = await swish.items.list({
  page: "page-cursor",
  limit: 20,
});
```

#### List all items (search query)

```typescript
const { data, error } = await swish.items.list({
  query: "product:123",
});
```

#### Create new item

```typescript
const { data, error } = await swish.items.create({ 
  productId: 123, variantId: 456, quantity: 1,
});
```

#### Delete multiple items

<pre class="language-typescript"><code class="lang-typescript"><strong>const { error } = await swish.items.delete([
</strong>  "item-id-1",
  "item-id-2",
]);
</code></pre>

#### Find item by ID

```typescript
const { data, error } = await swish.items.findById("item-id");
```

#### Update item by ID

```typescript
const { data, error } = await swish.items.updateById("item-id", {
  variantId: 456,
});
```

#### Delete item by ID

```typescript
const { error } = await swish.items.deleteById("item-id");
```

### Lists

{% hint style="success" %}
For more details, refer to the [Lists API reference](/swish-api/api-reference/lists.md).
{% endhint %}

#### List all lists

```typescript
const { data, error } = await swish.lists.list();
```

#### Create new list

```typescript
const { data, error } = await swish.lists.create({
  name: "Favourites",
});
```

#### Find list by ID

```typescript
const { data, error } = await swish.lists.findById("list-id");
```

#### Find list by ID (items sorted in custom order)

```typescript
const { data, error } = await swish.lists.findById("list-id", {
  sort: "customer"
});
```

#### Update list by ID

```typescript
const { data, error } = await swish.lists.updateById("list-id", {
  name: "New list name",
});
```

#### Delete list by ID

```typescript
const { error } = await swish.lists.deleteById("list-id");
```

#### Set  custom item order

```typescript
const { data, error } = await swish.lists.orderItems("list-id", {
  itemIds: ["item-id-2", "item-id-1"],
});
```

### Profiles

{% hint style="success" %}
For more details, refer to the [Profiles API reference](/swish-api/api-reference/profiles.md).
{% endhint %}

#### Create new token

```typescript
const { data, error } = await swish.profiles.createToken({
  customer: "gid://shopify/Customer/1234567",
})
```


---

# 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://developers.swish.app/libraries/api-client.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.
