From 14 April on, when you log in to MyTax you will activate Suomi.fi Messages. Tax correspondence will be delivered electronically only, in MyTax. Read more about the changes.
Code examples
Here is an example of a POST request in the C# programming language with a JSON message that uses client certificate authentication and adds a custom header:
This example downloads the certificate and associated private key from a file and adds it to the HttpClientHandler. It then creates an HttpClient using this handler. Next, it creates a JSON message, converts it to a string, and creates a StringContent token. It also adds a custom header "tax-softwarekey". Finally, it sends a POST request to the specified interface and prints the response.
Note that you must replace "path_to_your_certificate.pfx", "your_certificate_password", "your_software_key" and "https://your_api_endpoint" with the correct values.
Rajapinnan kutsuminen
using System;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Newtonsoft.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Load certificate from a file that also contains the private key
var certificate = new X509Certificate2("path_to_your_certificate.pfx", "your_certificate_password");
// Create HttpClientHandler and add the certificate
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(certificate);
// Create HttpClient using the handler
var client = new HttpClient(handler);
// Set request headers
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
// Add custom header for the API key
client.DefaultRequestHeaders.Add("vero-softwarekey", "your_software_key");
// Create JSON message body
var data = new { id = "72832", name = "John" };
var jsonData = JsonConvert.SerializeObject(data);
var contentData = new StringContent(jsonData, Encoding.UTF8, "application/json");
// Send the POST request
var response = await client.PostAsync("https://your_api_endpoint", contentData);
// Output the response
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}