Skip to main content
  • C#
  • Dart
  • Go
  • Java
  • JavaScript
  • Kotlin
  • PHP
  • Python
  • Ruby
  • Scala
  • Swift
Latest version: Install version 7 of the C#/.NET API clients by adding the Algolia.Search package from NuGet. For example:
dotnet add package Algolia.Search --version "7.*"

Building ASP.NET apps?

Check the additional information about dependency injection.
The C#/.NET API clients are open source and generated from OpenAPI specifications.

Test your installation

To test your installation, try running a short program that adds a record to a test index, searches your index, and prints the results.
1

Create account

If you haven’t already, create an Algolia account.
2

Copy code

Copy the following code into a new project or file. Replace ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with values from your account. Make sure to use an API key with addObject and search permissions.
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `search` ACL
var apiKey = "ALGOLIA_API_KEY";
var indexName = "test-index";

var client = new SearchClient(appID, apiKey);

// Create a new record
var record = new Dictionary<string, string>
{
    { "objectID", "object-1" },
    { "name", "test record" },
};

// Add record to an index
var saveResp = await client.SaveObjectAsync(indexName, record);

// Wait until indexing is done
await client.WaitForTaskAsync(indexName, saveResp.TaskID);

// Search for 'test'
var searchResp = await client.SearchAsync<Object>(
    new SearchMethodParams
    {
        Requests = new List<SearchQuery>
        {
            new SearchQuery(new SearchForHits { IndexName = indexName, Query = "test" })
        }
    }
);

Console.WriteLine(searchResp.ToJson());
In production, use environment variables for your credentials.
3

Run code

Run the code, depending on your development environment.
# For example:
dotnet run
If the command is successful, you’ll see the API response as a native object in your programming language.
I