Home > Use Public APIs for Job Information

Export to PDF

Use Public APIs for Job Information

We are upgrading to a new API for better user experience, stability, and easier integration. Visit our documentation page for more details.

To use the Cloud Backup for Dynamics 365 Public APIs, you must first go to the AvePoint Online Services interface and navigate to Administration > App registration page to register an app with the Dynamics.ReadWrite.All permission. For details, refer to Configure App Registrations.

When using the public APIs, you will need to provide the application client ID, Identity service URL, and API URL. To get the Identity service URL and the API URL for your data center, contact AvePoint support for assistance.

Request Information

Example

using IdentityModel;

using IdentityModel.Client;

using Microsoft.IdentityModel.Tokens;

using Newtonsoft.Json;

using System;

using System.Collections.Generic;

using System.IdentityModel.Tokens.Jwt;

using System.IO;

using System.Net.Http;

using System.Security.Claims;

using System.Security.Cryptography.X509Certificates;

using System.Text;

using System.Threading.Tasks;

namespace Demo

{

    internal class Program

    {

        // Install-Package IdentityModel

        // Install-Package System.IdentityModel.Tokens.Jwt

        static string **clientId** = "";

        static string **identityUrl** = "https://identity-public..com";

        static string **apiUrl** = "https://graph-public.*.com/dynamicsbackup";

        static async Task Main(string[] args)

        {

            var client = new HttpClient();

            var disco = await client.GetDiscoveryDocumentAsync(identityUrl);

            if (disco.IsError)

            {

                Console.WriteLine(disco.Error);

                return;

            }

            var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest

            {

                Address = disco.TokenEndpoint,

                ClientAssertion = new ClientAssertion()

                {

                    Type = OidcConstants.ClientAssertionTypes.JwtBearer,

                    Value = CreateClientAuthJwt(disco)

                },

                Scope = "dynamics.readwrite.all",

            });

            if (tokenResponse.IsError)

            {

                Console.WriteLine(tokenResponse.Error);

                return;

            }

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + tokenResponse.AccessToken);

            string filter = JsonConvert.SerializeObject(new

            {

                pageInfo = new

                {

                    currentPage = 1,

                    pageSize = 5,

                },

                startTime = 1385587340740,

                endTime = 1785587340740,

                type = 1,

                status = 3,

                organizationId = "5c47faf1-8d22-43df-9140-b200174fe0e7",

                objectType = 1

            });

            HttpContent content = new StringContent(filter, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(apiUrl + "/api/Job/GetJobs", content);

            string result = await response.Content.ReadAsStringAsync();

            // You can continue configuring to export the response information to CSV or Excel file. 

            // ...

        }

        private static string CreateClientAuthJwt(DiscoveryDocumentResponse response)

        {

            // set exp to 5 minutes

            var tokenHandler = new JwtSecurityTokenHandler { TokenLifetimeInMinutes = 5 };

            var securityToken = tokenHandler.CreateJwtSecurityToken(

                // iss must be the client_id of our application

                issuer: clientId,

                // aud must be the identity provider (token endpoint)

                audience: response.TokenEndpoint,

                // sub must be the client_id of our application

                subject: new ClaimsIdentity(

                  new List<Claim> { new Claim("sub", clientId),

                  new Claim("jti", Guid.NewGuid().ToString())}),

                // sign with the private key (using RS256 for IdentityServer)

                signingCredentials: new SigningCredentials(

                  new X509SecurityKey(new X509Certificate2(LoadCertificate())), "RS256")

            );

            return tokenHandler.WriteToken(securityToken);

        }

        private static X509Certificate2 LoadCertificate()

        {

            string fileName = Path.Combine(AppContext.BaseDirectory, "dynamics.pfx");

            string password = "**";

            return new X509Certificate2(fileName, password);

        }

    }

}

Details

ElementDescriptionTypeRequired?
pageInfo.currentPageSets the starting number of the page to get the jobs. The default value is 1.intYes
pageInfo.pageSizeSets the number of jobs to display on one page. The default value is 10.intYes
startTimeSets a start time (UTC time) for the time range.longYes
finishTimeSets an end time (UTC time) for the time range.longYes
typeSets the job types that you want to get.Enum0 (for All)1 (for Backup)2 (for Restore)Yes
statusSets the job statusEnum2 (for In Progress)3 (for Finished)4 (for Failed)7 (for Finished with Exception)No
organizationIdSets the organization that you want to get.GUIDNo
objectTypeSets the module type of the jobs to get.Enum1 (for Customer Engagement)2 (for Unified Operations)No

Response Information

Example

{

    "totalNumber": 19,

    "result": [

        {

            "module": "Customer Engagement",

            "type": "Backup",

            "jobId": "DCFB2023063006040283662955",

            "startTime": 1688105042837,

            "finishTime": 1688345910663,

            "durationHours": 66.90772944444444,

            "status": "Finished",

            "successfulEntity": 1,

            "failedEntity": 0,

            "skippedEntity": 0,

            "warningEntity": 0,

            "totalEntity": 1,

            "successfulRecord": 73,

            "failedRecord": 0,

            "skippedRecord": 0,

            "warningRecord": 0,

            "totalRecord": 73,

            "backupSize": 691632,

            "organizationId": "9f9c9bc4-8893-4db7-8056-412d5ca02d5d",

            "organizationName": "test051801"

        },

        {

            "module": "Customer Engagement",

            "type": "Backup",

            "jobId": "DCFB2023060102422073855438",

            "startTime": 1685587340740,

            "finishTime": 1685587414070,

            "durationHours": 0.020369444444444443,

            "status": "Finished",

            "successfulEntity": 9,

            "failedEntity": 0,

            "skippedEntity": 0,

            "warningEntity": 0,

            "totalEntity": 9,

            "successfulRecord": 674,

            "failedRecord": 0,

            "skippedRecord": 0,

            "warningRecord": 0,

            "totalRecord": 674,

            "backupSize": 4871824,

            "organizationId": "5c47faf1-8d22-43df-9140-b200174fe0e7",

            "organizationName": "org17a1a2c5"

        }

    ],

    "currentPage": 1,

    "pageSize": 2

}

Details

ElementDescriptionType
totalNumberThe total number of the retrieved jobs.int
currentPageThe page number.int
pageSizeThe number of jobs displayed on this page.int
resultA list of jobs.List