cancel
Showing results for 
Search instead for 
Did you mean: 

how to call afaria api to add Certificate authority server property in a afaria7 sp5 tenant

Former Member
0 Kudos

Hi Expert,

we are working on afaria apis to automate the process of assigning CA server property for a tenant . where i am call server property api service.

but i don't know how to set property like server address, CA type etc. for a tenant.

any help will be apreciated.

BR,

Saurabh

Accepted Solutions (1)

Accepted Solutions (1)

jtaylor
Active Participant
0 Kudos

What type of CA were you attempting to add? For a simple SCEP CA entry, see below:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using ServerProps_AddCA.AfariaServerProperties;

namespace ServerProps_AddCA

{

    class Program

    {

        static void Main(string[] args)

        {

            string apiAddress = "10.10.10.10";

            string apiUserDomain = "domain.com";

            string apiUserName = "afaria";

            string apiUserPass = "mysupersecretpassword";

            string serverTransmitterID = "mytransmitterid";

            string response = string.Empty;

            Console.Write("Enter the API Server address or hit enter for default: ");

            response = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(response))

            {

                apiAddress = response;

                Console.Write("Enter the API Service Account UserName or hit enter for default: ");

                response = Console.ReadLine();

                if (!string.IsNullOrWhiteSpace(response))

                {

                    apiUserName = response;

                    Console.Write("Enter the API Service Account User Domain or hit enter for default: ");

                    response = Console.ReadLine();

                    if (!string.IsNullOrWhiteSpace(response))

                    {

                        apiUserDomain = response;

                    }

                    Console.Write("Enter the API Service Account User Password or hit enter for default: ");

                    response = Console.ReadLine();

                    if (!string.IsNullOrWhiteSpace(response))

                    {

                        apiUserPass = response;

                    }

                }

            }

            using (ServerPropertiesServiceClient svcServerProperties = new ServerPropertiesServiceClient("NetTcpBinding_IServerPropertiesService"

                                                                                                    , "net.tcp://" + apiAddress + ":7982/AfariaService/ServerProperties"))

            {

                svcServerProperties.ClientCredentials.Windows.ClientCredential.Domain = apiUserDomain;

                svcServerProperties.ClientCredentials.Windows.ClientCredential.UserName = apiUserName;

                svcServerProperties.ClientCredentials.Windows.ClientCredential.Password = apiUserPass;

                svcServerProperties.InitContext(Guid.NewGuid().ToString());

                Console.Write("Enter the Tenant ID # or hit enter for system tenant(0): ");

                int tenantID = 0;

                response = Console.ReadLine();

                if (!string.IsNullOrWhiteSpace(response))

                {

                    int.TryParse(response, out tenantID);

                }

                svcServerProperties.SetTenantIdContext(tenantID);

                svcServerProperties.SetServerIdContext(serverTransmitterID);

                string caName = "New CA-" + Guid.NewGuid().ToString("N");

                string caDescription = "New CA Description";

                string caAddress = "127.0.0.1";

                CertificateAuthorityConfigurationScep caConfig = new CertificateAuthorityConfigurationScep();

                caConfig.CertificateRequest = new CertificateRequestV002();

                caConfig.ServerAccess = new ServerAccessSettings();

                caConfig.ServerAccess.Address = caAddress;

                caConfig.CertificateRenewalDays = 21;

             

                try

                {

                    //if (svcServerProperties.ValidateCertificateAuthoritySettingsV002(caConfig, null, 60))

                    //{

                    Console.WriteLine("Attempting to add CA entry...");

                    svcServerProperties.AddCertificateAuthorityDefinedSettingInfoV002(caName, caDescription, caConfig);

                    Console.WriteLine("Hooray! Success!");

                    //}

                }

                catch(Exception ex)

                {

                    Console.WriteLine("Exception occurred: " + ex.Message + "\r\n" + ex.StackTrace);

                    if(ex.InnerException != null)

                    {

                        Console.WriteLine("\r\nInner exception: " + ex.InnerException.Message + "\r\n"+ ex.InnerException.StackTrace);

                    }

                }

                if (svcServerProperties.ChannelFactory.State != System.ServiceModel.CommunicationState.Faulted)

                {

                    svcServerProperties.CloseContext();

                }

            }

            Console.Write("\r\n\r\nPress a key to exit...");

            Console.ReadKey();

        }

    }

}

Former Member
0 Kudos

Hi John,

Thanks for your reply it worked very well . now i want to fetch no. of device registered for a tenant how to get that through api and also linking app policy or configuration policy to group through api. can you provide some sample code for SchemaQuery & StoredQueries

We are having issues in usage of the Schema Query for a defined Query ID.

Thanks,

Saurabh

0 Kudos

Hi Saurabh,

Please create a new Discussion for the new question.

Thanks, Mike (Moderator)

Answers (0)