Contact me!
Eric Håård
+46 (0) 73 375 86 06

Job Information

C# code snippets explaining how to query job status.

After an update request have been sent, you can query Storm Connect to view status of your job.
The basic status to check is StatusId, which translates as:

  • 1 = In Progress
  • 2 = Completed
  • 3 = Error

Example code:

private static void Main()
{
    var serviceUrl = "https://stormstage.enferno.se/StormConnect/4.0/api/";
    var applicationId = 0;
    var secretKey = Guid.NewGuid();

    // List details for specific job
    var job = ImportMethod(serviceUrl, applicationId, secretKey);
    // ...
    // Recheck specific job to see updated status
    var specificJob = GetJob(serviceUrl, applicationId, secretKey, job.JobId);

    // List all jobs
    var allJObs = GetJobs(serviceUrl, applicationId, secretKey);
}

public static JobDto GetJob(
    string serviceUrl, int applicationId, Guid secretKey, int jobId)
{
    using (var httpClient = new HttpClient())
    {
        var credentials =
                Encoding.ASCII.GetBytes($"{applicationId}:{secretKey.ToString("D")}");

        // Base64Encoded Basic authentication is used
        var credentialsToBase64 = Convert.ToBase64String(credentials);
        httpClient.DefaultRequestHeaders.Authorization = 
                    new AuthenticationHeaderValue("Basic", credentialsToBase64);

        var jobResponse = httpClient.GetStringAsync($"{serviceUrl}job/{jobId}").Result;
        return JsonConvert.DeserializeObject<JobDto>(jobResponse);
    }
}

public static List<JobDto> GetJobs(
    string serviceUrl, int applicationId, Guid secretKey)
{
    using (var httpClient = new HttpClient())
    {
        var credentials =
                Encoding.ASCII.GetBytes($"{applicationId}:{secretKey.ToString("D")}");

        // Base64Encoded Basic authentication is used
        var credentialsToBase64 = Convert.ToBase64String(credentials);
        httpClient.DefaultRequestHeaders.Authorization = 
                    new AuthenticationHeaderValue("Basic", credentialsToBase64);

        var allJobsResponse = httpClient.GetStringAsync($"{serviceUrl}job").Result;
        return JsonConvert.DeserializeObject<List<JobDto>>(allJobsResponse);
    }
}