Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Eksemplet er utroligt simplificeret og peger direkte på “GetJobannonce“ “GetVisninger“ endpointet og bør derfor tilrettes efter best practise før brug i produktion.

...

Code Block
breakoutModefull-width
languagec#
// Create a HttpClient with the certificate
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;

// Setup authorization by including a certificate in the HttpClient
var httpClientHandler = new HttpClientHandler();
var certificateThumbprint = "Dit certifikat thumbprint9f68c4589b44ff8286702e63079f0e76f60e7d2f";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Find(X509FindType.FindBySubjectNameFindByThumbprint, certificateThumbprint, validOnly: false)[0];
httpClientHandler.ClientCertificates.Add(certificate);
var httpClient = new HttpClient(httpClientHandler);

// API endpoint URL
const varstring apiUrl = "https://virksomhedsindsatst1virksomhedsindsatst10.startest.dk/v1v2/Jobannonce/5832974visninger?fraDato=2024-01-01"; 

// Add headers to the request
httpClient.DefaultRequestHeaders.Add("x-activeOrganisation", "{\"OrganisationType\":24,\"OrganisationCode\":\"Portal CVR\"}");
httpClient.DefaultRequestHeaders.Add("x-requestUserMetadata", "{\"RequestUserStructure\":{\"UserFullName\":\"Full Name\",\"RequestUserType\":3,\"UserIdentifier\":\" \",\"UserEmailEmail\":\"test@test.dk\"},\"RequestOrganisationStructure\":{\"OrganisationType\":24,\"OrganisationCode\":\"Portal bruger CVR\"},\"RegistrationDateTime\":\"2023-07-12T09:41:38\"}");
try
{
    	// Make a GET request with the ID parameter
    	var response = await httpClient.GetAsync($"{apiUrl}");
	// Ensure
the response was successful 	response.EnsureSuccessStatusCode();
	
    
    // Read the response content as JSON
    	var responseContent = await response.Content.ReadAsStringAsync();
	// Deserialize
the JSON response dynamically 	dynamic jsonResponse = JsonSerializer.Deserialize<dynamic>(responseContent);
	
    
    // Use the jsonResponse object as needed
    	// ...
    	Console.WriteLine("API call successful!");
}
catch (Exception ex)
{
    	Console.WriteLine($"Error: {ex.Message}");
}