var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.myapi.rest/api/ping");
request.Headers.Add("Authorization", "Bearer <API_KEY>");
var content = new StringContent("", null, "text/plain");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
We use standard HTTP status codes. Error payloads are JSON:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
"title": "API Key validation error",
"status": 500,
"detail": "The API key provided could not be validated",
"instance": "/api/ping"
}
using System.Net.Http;
using System.Text;
var http = new HttpClient();
http.DefaultRequestHeaders.Add("Authorization", "Bearer <API_KEY>");
var body = @"{
""url"": ""https://example.com/landingpage"",
""type"": ""png"",
""logo_url"": ""https://example.com/assets/logo.png"",
""campaign_name"": ""spring-campaign""
}";
var res = await http.PostAsync(
"https://myapi.rest/qrcode",
new StringContent(body, Encoding.UTF8, "application/json")
);
var json = await res.Content.ReadAsStringAsync();
System.Console.WriteLine(json);
using System.Net.Http;
using System.Text;
var http = new HttpClient();
http.DefaultRequestHeaders.Add("Authorization", "Bearer <API_KEY>");
var body = @"{
""data"": ""1234567"",
""format"": ""UPC_E"",
""width"": 200,
""height"": 50,
""margin"": 0,
""campaign_name"": ""spring-campaign""
}";
var res = await http.PostAsync(
"https://myapi.rest/barcode",
new StringContent(body, Encoding.UTF8, "application/json")
);
var json = await res.Content.ReadAsStringAsync();
System.Console.WriteLine(json);
using System.Net.Http;
using System.Text;
var http = new HttpClient();
http.DefaultRequestHeaders.Add("Authorization", "Bearer <API_KEY>");
var body = @"{
""imagedata"": ""<BASE_64_DATA>"",
""imagename"": ""filename.jpg""
}";
var res = await http.PostAsync(
"https://myapi.rest/image",
new StringContent(body, Encoding.UTF8, "application/json")
);
var json = await res.Content.ReadAsStringAsync();
System.Console.WriteLine(json);