.NET
Add the Zernio NuGet package and call every Zernio API endpoint from C# with a reusable HttpClient.
Zernio is the official C# client for the Zernio API. Install it with dotnet add package Zernio. The package is on NuGet and the source on GitHub.
First call
dotnet add package Zernio
export ZERNIO_API_KEY="sk_..."Set the API key on a Configuration, then construct the API class with an HttpClient you reuse. BasePath ends at /api: every method appends its own /v1 path, so the /v1 you see in the curl samples is already there. This program publishes a post to a connected LinkedIn account; accountId comes from GET /v1/accounts (Step 4 of the quickstart).
using System;
using System.Collections.Generic;
using System.Net.Http;
using Zernio.Api;
using Zernio.Client;
using Zernio.Model;
Configuration config = new Configuration();
config.BasePath = "https://zernio.com/api";
config.AccessToken = Environment.GetEnvironmentVariable("ZERNIO_API_KEY");
HttpClient httpClient = new HttpClient();
HttpClientHandler httpClientHandler = new HttpClientHandler();
var postsApi = new PostsApi(httpClient, config, httpClientHandler);
var request = new CreatePostRequest(
content: "Hello from the Zernio .NET SDK",
platforms: new List<CreatePostRequestPlatformsInner>
{
new CreatePostRequestPlatformsInner(platform: "linkedin", accountId: "66b2e19d8c3f5a7e9d0b1c2d"),
},
publishNow: true
);
try
{
var result = postsApi.CreatePost(request);
Console.WriteLine(result);
}
catch (ApiException e)
{
Console.WriteLine("Status code: " + e.ErrorCode);
Console.WriteLine("Message: " + e.Message);
Console.WriteLine(e.ErrorContent);
}Response (201):
{
"post": {
"_id": "65f1c0a9e2b5af0012ab34cd",
"status": "published",
"platforms": [
{
"platform": "linkedin",
"status": "published",
"platformPostUrl": "https://www.linkedin.com/feed/update/..."
}
]
}
}Methods
Each method is named after the operationId of the endpoint it calls, on a class per API tag in Zernio.Api: PostsApi.CreatePost, AccountsApi.ListAccounts, ProfilesApi.CreateProfile, AnalyticsApi.GetAnalytics, WebhooksApi.CreateWebhookSettings, WorkflowsApi.CreateWorkflow. Request models live in Zernio.Model.
Method reference
Every endpoint and model in the GitHub README
API reference
Request and response schemas for every endpoint
How it behaves
One HttpClient serves every API class
Pass the same HttpClient and HttpClientHandler to each API class you construct, as the first call does. In ASP.NET Core, register the class with IHttpClientFactory instead, and pass the same config:
services.AddHttpClient<PostsApi>(httpClient => new PostsApi(httpClient, config, httpClientHandler));The Configuration is what carries AccessToken, so a registration that constructs new PostsApi(httpClient) alone sends no API key and every call returns 401.
CreatePost accepts an idempotency key
Pass xRequestId: (a Guid) to send the x-request-id header: postsApi.CreatePost(request, xRequestId: Guid.NewGuid()). A retry with the same value and the same content within 24 hours returns the original post instead of a duplicate-content 409. To protect a retry whose body can differ, send an Idempotency-Key header instead (idempotency).
Errors throw Zernio.Client.ApiException
A non-2xx response throws ApiException; ErrorCode is the HTTP status and ErrorContent the JSON envelope. Running the first call twice within 24 hours throws it with ErrorCode 409, because the same content is already published to that account:
{
"error": "This exact content is already scheduled, publishing, or was posted to this account within the last 24 hours.",
"details": {
"accountId": "66b2e19d8c3f5a7e9d0b1c2d",
"platform": "linkedin",
"existingPostId": "65f1c0a9e2b5af0012ab34cd"
}
}Change the content, or send an idempotency key. The error handling guide lists every code.
Related
- Quickstart: API key, profile, account and first post in 5 calls.
- Idempotency: what
xRequestIddoes. - Error handling: the envelope inside
ApiException. - Rate limits: what a
429means and how to back off. - SDKs: the other 7 clients.