---
title: "DWS Processor API with C#"
canonical_url: "https://www.nutrient.io/guides/dws-processor/supported-languages/csharp/"
md_url: "https://www.nutrient.io/guides/dws-processor/supported-languages/csharp.md"
last_updated: "2026-05-26T01:23:09.641Z"
description: "Learn how to use Nutrient DWS Processor API to process documents with HTTP requests and RestSharp in this step-by-step guide."
---

# DWS Processor API with C#

With Nutrient DWS Processor API, you can process your documents by making HTTP requests to one of our [50+ API tools](https://dashboard.nutrient.io/processor-api/playground/). You can make a single request to one tool or combine API actions to generate, edit, OCR, and convert your document (1 document can have multiple API actions).

This guide explains how to use C# to make HTTP requests with our API by:

1. Creating a new project

2. Preparing the request

3. Executing the request

You’ll use [RestSharp](https://restsharp.dev/) to make HTTP requests.

## Creating a new project

You’ll need a.NET project. The easiest way is to use the [.NET CLI](https://docs.microsoft.com/dotnet/core/tools/) tool that ships with the [.NET SDK](https://docs.microsoft.com/dotnet/core/sdk) and create a new project based on the Console Application template:

```shell

dotnet new console --name PspdfkitApiDemo

```

Then, switch to the newly created project directory:

```shell

cd PspdfkitApiDemo

```

Now you can add a `RestSharp` dependency:

```shell

dotnet add package RestSharp

```

Finally, you’ll need to add `document.pdf` and `logo.png` files to the root of your project. You can use the sample files provided by us — [document.pdf](https://www.nutrient.io/assets/guides/dws-processor/watermark/document.pdf) and [logo.png](https://www.nutrient.io/assets/guides/dws-processor/watermark/logo.png) — or use your own.

Your project is now ready to make requests to Nutrient DWS Processor API. Next, you’ll add your main entry point to the app. Open the `Program.cs` file in the new project and make sure it has the `Program` class with the `Main` method. You can also add all the imports you’re going to use:

```csharp

using System;
using System.IO;
using System.Net;
using RestSharp;

namespace PspdfkitApiDemo
{
  class Program
  {
    static void Main(string[] args)
    {
      // Implement your call to Nutrient DWS Processor API here.
    }
  }
}

```

Next, you’ll prepare the request.

## Preparing the request

For this example, you’ll add an image watermark to your document. To do so, you need to create an `instructions` JSON object:

```csharp

var instructions = new JsonObject
{
  ["parts"] = new JsonArray
  {
    new JsonObject
    {
      ["file"] = "document"
    }
  },
  ["actions"] = new JsonArray
  {
    new JsonObject
    {
      ["type"] = "watermark",
      ["image"] = "logo",
      ["width"] = "25%"
    }
  }
};

```

Here, you’re just building a JSON object via the JSON API built in to.NET. For examples of how the watermark API can be used (for example, adding multiple watermarks to the document, watermarking the last page of the document, and watermark alignments), refer to our [PDF watermark API](https://www.nutrient.io/api/pdf-watermark-api/) page.

Next, you can create a `RestRequest` with the required authorization header, the instructions, and all required files:

```csharp

var request = new RestRequest(Method.POST).AddHeader("Authorization", "Bearer your_api_key_here").AddFile("document", "document.pdf").AddFile("logo", "logo.png").AddParameter("instructions", instructions.ToString());

```

Here, you assemble your `multipart/form-data` body containing the JSON instructions, your `document.pdf` that will be watermarked, and the `logo.png` that you’ll use as a watermark.

You want to save the successful response to a file. You could execute the request and save the resulting binary data to a file, but this requires reading the whole response into memory. A better solution is to stream the response to a file. For this, you’ll set `AdvancedResponseWriter` on your request:

```csharp

request.AdvancedResponseWriter = (responseStream, response) =>
{
  // Check if this is an OK response (i.e. with HTTP status 200).
  if (response.StatusCode == HttpStatusCode.OK)
  {
    // Stream the response with the processed document to a file, "result.pdf".
    using (responseStream)
    {
      using var outputFileWriter = File.OpenWrite("result.pdf");
      responseStream.CopyTo(outputFileWriter);
    }
  }
  else
  {
    // For the sake of this example, you'll write any error responses to the console.
    var responseStreamReader = new StreamReader(responseStream);
    Console.Write(responseStreamReader.ReadToEnd());
  }
};

```

## Executing the request

Finally, all that’s left is to actually make the request. You need a new `RestClient` configured to make requests to the Nutrient DWS Processor API `/build` endpoint:

```csharp

var client = new RestClient("https://api.nutrient.io/build");

```

Now, use it to execute the request:

```csharp

client.Execute(request);

```

This will actually send your request to Nutrient DWS Processor API and save the resulting PDF in the root folder as `result.pdf`.

At this point, you can run our example directly in the terminal:

```shell

dotnet run

```

After it finishes, you’ll see `result.pdf` appear in your project’s folder. And that’s it — you now have everything set up to use Nutrient DWS Processor API from C#.

While this example made use of our watermarking API, this same approach can be used for all our available [API tools](https://dashboard.nutrient.io/processor-api/playground/).

## Complete code

For your convenience, the complete code is below:

```csharp

using System;
using System.IO;
using System.Net;
using RestSharp;

namespace PspdfkitApiDemo
{
  class Program
  {
    static void Main(string[] args)
    {
      var client = new RestClient("https://api.nutrient.io/build");

      var instructions = new JsonObject
      {
        ["parts"] = new JsonArray
        {
          new JsonObject
          {
            ["file"] = "document"
          }
        },
        ["actions"] = new JsonArray
        {
          new JsonObject
          {
            ["type"] = "watermark",
            ["image"] = "logo",
            ["width"] = "25%"
          }
        }
      };

      var request = new RestRequest(Method.POST).AddHeader("Authorization", "Bearer your_api_key_here").AddFile("document", "document.pdf").AddFile("logo", "logo.png").AddParameter("instructions", instructions.ToString());

      request.AdvancedResponseWriter = (responseStream, response) =>
      {
        if (response.StatusCode == HttpStatusCode.OK)
        {
          using (responseStream)
          {
            using var outputFileWriter = File.OpenWrite("result.pdf");
            responseStream.CopyTo(outputFileWriter);
          }
        }
        else
        {
          var responseStreamReader = new StreamReader(responseStream);
          Console.Write(responseStreamReader.ReadToEnd());
        }
      };

      client.Execute(request);
    }
  }
}

```
---

## Related pages

- [Supported languages](/guides/dws-processor/supported-languages.md)
- [DWS Processor API with PHP](/guides/dws-processor/supported-languages/php.md)
- [Enable enhanced code completion and documentation for Claude Code using the Nutrient DWS SDK.](/guides/dws-processor/supported-languages/javascript.md)
- [DWS Processor API with other languages](/guides/dws-processor/supported-languages/other.md)
- [Enable enhanced code completion and documentation for Claude Code using the Nutrient DWS SDK.](/guides/dws-processor/supported-languages/python.md)
- [DWS Processor API with Java](/guides/dws-processor/supported-languages/java.md)

