Follow

Get Job Status example

Description

This sample shows how to retrieve a job status, where the particular job is referenced by its job id.
The returned structure contains the string information of the status being it one of the folllowing: NotAssigned, Assigned, Accepted, InProgress, Done.
It is assumed that a valid api key is provided into the function.

C#.NET

        ...
        JobStatusEnum? status = GetJobStatus(apikey, 321949);
        string textStatus = status.ToString();
        ...


        public enum JobStatusEnum
        {
            NotAssigned = 1,
            Assigned = 2,
            Accepted = 3,
            InProgress = 4,
            Done = 5
        }

        public class JobStatus
        {
            public int JobId { get; set; }
            public JobStatusEnum Status { get; set; }
        }

        protected JobStatusEnum? GetJobStatus(string apikey, int jid)
        {
            var cli = new RestClient("https://api.jobdispatch.sygic.com/api/v1");
            var request = new RestRequest("jobStatus", Method.GET);
            request.AddQueryParameter("id", jid.ToString());
            request.AddQueryParameter("includeDeleted", "false");
            request.AddHeader("X-api_key", apikey);
            request.RequestFormat = DataFormat.Json;
            JobStatusEnum? jobStatusResult = null;
            try
            {
                var response = (RestResponse)cli.Execute(request);
                var jsonConverter = new RestSharp.Deserializers.JsonDeserializer();
                var jobStatus = jsonConverter.Deserialize<JobStatus>(response);
                if (jobStatus != null)
                {
                    jobStatusResult = jobStatus.Status;
                }
            }
            catch (Exception e)
            {}

            return jobStatusResult;
        }

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments