# Create & manage campaigns

{% hint style="warning" %} <mark style="color:orange;">**IMPORTANT! FOR BACK-END USE ONLY!**</mark> Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.
{% endhint %}

### Basic concepts

There are few basic concepts that you should be aware to generate claim links with Linkdrop SDK

***Links*** are stored in ***batches***, which are themselves a part of the ***campaigns***. Campaign can have several batches, and you can also add more links into different batches within the campaign.

1. You should first create a campaign using Dashboard, see [Keys and installation](/linkdrop-dashboard/dashboard-sdk-and-api/keys-and-installation.md), and save your **campaignId**, **signerKey** and **encryptionKey**
2. Get a campaign by using **campaignId**, **signerKey** and **encryptionKey**
3. **Create a new batch.** You will also see in the Dashboard and be able to download links in CSV there
4. Use **batch.addLinks** to add more links to a batch&#x20;

### Managing Campaigns

{% hint style="warning" %} <mark style="color:orange;">**IMPORTANT! FOR BACK-END USE ONLY!**</mark> Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.
{% endhint %}

After you have created a campaign using Linkdrop Dashboard, you can use SDK to manage the campaign. Using SDK you can:

* fetch campaign data
* create a new batch of claim links
* add claim links to an existing batch
* fetch created claim links
* activate or deactivate links

**Getting Campaign**

To be able to do all that, first you need to fetch initialize campaign object

```
const campaign = await sdk.getCampaign(
  campaignId: string,
  signerKey: string,
  encryptionKey: string
)
```

Get all params from the campaign page on Dashboard:

* `campaignId`: ID of the campaign that you want to retrieve information about.
* `signerKey`: private key used to create claim links. <mark style="background-color:orange;">**(NEVER EXPOSE SIGNER KEY PUBLICLY)**</mark>
* `encryptionKey`: private key used to encode and decode sensitive data stored on server <mark style="background-color:orange;">**(NEVER EXPOSE ENCRYPTION KEY PUBLICLY)**</mark>

{% hint style="warning" %} <mark style="color:orange;">**IMPORTANT! FOR BACK-END USE ONLY!**</mark> Managing campaigns requires secret keys that should never be exposed to public. Use campaign methods on a back-end and never within a front-end app.
{% endhint %}

The returned `campaign` object has campaign data and addtional methods to manage the campaign.

```
console.log(campaign.data)
```

### Creating claim links

**Creating new batch**

To create a batch of claim links for the campaign, use the `campaign.createBatch` method

```
const batch = await campaign.createBatch(
  [{ 
    id: string,
    amount: string,
    links: string,
    weiAmount?: string // optional parameter, The default value is `0`.
  }],
  // optional parameters
  {
    batchDescription: string,
    shortCodeLength: number,
    shortCodeMixRegister: boolean,
    expirationTime: string
  }
)
```

It takes two parameters:

* `linkData`: This is a required array of objects that contain information about the links to be created. Each object in the array must have the following properties:
  * `id`: token ID for ERC721/ERC1155 campaigns. For ERC20 campaigns, id is not provided.
  * `amount`: amount of tokens per link for ERC20/ERC1155 campaigns. For ERC721 campaigns, amount is not provided.
  * `links`: number of links to create.
  * `weiAmount`: amount of network tokens (ETH/MATIC) to be sent to receiver on claim. Campaign contract should have enough network tokens before claim. Top up the campaign contract in advance manually. The default value is `0`.
* `options`: This is an optional object that can contain the following properties:
  * `batchDescription`: This is an optional string property that specifies the description of the batch. The default value is "Created by SDK".
  * `shortCodeLength`: The length of claimCode. The default value is `12`.
  * `shortCodeMixRegister`: Should the claim code contain uppercase and lowercase symbols. The default value is `true`.
  * `expirationTime`: Timestamp for the link expiration date. The default value is `1900000000000`.

The returned `batch` object contains information related to the specified batch and methods to manage it.

**Getting Batches**

To retrieve all batches associated with the campaign, call the `campaign.getBatches` method:

```
const batches = await campaign.getBatches()
```

**Getting Batch**

To manage a batch, first you need to retrieve it by ID:

```
const batch = await campaign.getBatch(
  batchId: string
) 
```

The returned `batch` object contains information related to the specified batch and methods to manage it.

### Batch methods

**Adding Links to an existing batch**

To add claim links to an existing batch, call the `batch.addLinks` method:

```
const links = await batch.addLinks(
  [{ 
    id: string, 
    amount: string, 
    links: string, 
    weiAmount: string // optional parameter, The default value is `0`.
  }], {
    // optional parameters
    shortCodeLength: number,
    shortCodeMixRegister: boolean,
    expirationTime: string
  }
) 
```

&#x20;It takes two parameters and returns an array of link IDs:

1. `links`: An array of link objects that contain the following properties:

* `id`: The token ID (required for ERC721/ERC1155 campaigns).
* `amount`: The amount of tokens per link (required for ERC20/ERC1155 campaigns).
* `links`: The number of links to be created.
* `weiAmount`: The amount of native tokens that should be sent to the proxy contract address manually. The default value is `0`.

2. `options`: This is an optional object that can contain the following properties:

* `shortCodeLength`: The length of claimCode. The default value is `12`.
* `shortCodeMixRegister`: Should the claim code contain uppercase and lowercase symbols. The default value is `true`.
* `expirationTime`: Timestamp for the link expiration date. The default value is `1900000000000`.

**Getting Links**

To fetch all links created for that batch, use the `batch.getLinks` method:

```
const links = await batch.getLinks()
```

### Deactivating / reactivating links

{% hint style="info" %}
Individual link deactivation is only available when using the SDK. If the user will follow the link that has been deactivated, he will see a corresponding message "Link deactivated"
{% endhint %}

**Deactivate Link**

To deactivate link:

```
const success = await campaign.deactivate(
  claimCode: string
)
```

Parameters:

* `claimCode`: The `claimCode` parameter from the claim link URL.

**Reactivate Link**

To reactivatate previosly deactivated link:

```
const success = await campaign.reactivate(
  claimCode: string
) 
```

Parameters:

1. `claimCode`: The `claimCode` parameter from the claim link URL.


---

# 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.linkdrop.io/linkdrop-dashboard/dashboard-sdk-and-api/create-and-manage-campaigns.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.
