Export (0) Print
Expand All

Sign Up Customer in C#

The following example shows how to create a new reseller managed customer using the Customer Management SignupCustomer service operation.

This example has been developed and run within the environment described in Getting Started Using C# and Visual Basic with Bing Ads Services.

System_CLiX_note Note

This example uses the UserName and Password elements for authentication. For Managing User Authentication with OAuth, replace the UserName and Password elements with the AuthenticationToken, which is your OAuth access token.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using SignupCustomer.BingAds.CustomerManagement;

namespace SignupCustomer
{
    class Program
    {
        private static CustomerManagementServiceClient m_customerService = null;

        // Specify your credentials.

        private static string m_password = "<PasswordGoesHere>";
        private static string m_userName = "<UsernameGoesHere>";
        private static string m_token = "<DeveloperTokenGoesHere>";

        // Specify the reseller’s customer ID.

        private const long m_resellerCustomerId = <ResellerIDGoesHere>; 

        // This example shows how to sign up a customer.

        static void Main(string[] args)
        {
            try
            {
                m_customerService = new CustomerManagementServiceClient("BasicHttpBinding_ICustomerManagementService");

                AddCustomer(m_resellerCustomerId);

                m_customerService.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);

                if (m_customerService != null)
                {
                    m_customerService.Abort();
                    m_customerService = null;
                }
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);

                if (m_customerService != null)
                {
                    m_customerService.Abort();
                    m_customerService = null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                if (m_customerService != null)
                {
                    m_customerService.Abort();
                    m_customerService = null;
                }
            }
        }

        // Sign up a customer.

        static private void AddCustomer(long resellerId)
        {
            SignupCustomerRequest request = new SignupCustomerRequest();
            SignupCustomerResponse response = null;
            Customer customer = null;
            User user = null;
            Account account = null;

            customer = GetCustomerData();
            user = GetUserData();
            account = GetAccountData();

            try
            {
                request.UserName = m_userName;
                request.Password = m_password;
                request.DeveloperToken = m_token;
                request.ApplicationScope = ApplicationType.Advertiser;
                request.ParentCustomerId = resellerId;
                request.Customer = customer;
                request.User = user;
                request.Account = account;

                response = m_customerService.SignupCustomer(request);

                Console.WriteLine("Customer: {0} ({1})", customer.Name, response.CustomerId);
                Console.WriteLine("User: {0} ({1})", user.UserName, response.UserId);
                Console.WriteLine("Account: {0} ({1})", account.Name, response.AccountId);
            }
            catch (FaultException<AdApiFaultDetail> fault)
            {
                foreach (AdApiError error in fault.Detail.Errors)
                {
                    Console.WriteLine("Error code: {1}\nMessage: {0}\nDetail: {2}\n", error.Message, error.Code, error.Detail);
                }
            }
            catch (FaultException<ApiFault> fault)
            {
                foreach (OperationError error in fault.Detail.OperationErrors)
                {
                    Console.WriteLine("Error code: {1}\nMessage: {0}\nDetails: {2}\n", error.Message, error.Code, error.Details);
                }
            }
        }

        // Populate the Customer object.

        static private Customer GetCustomerData()
        {
            Customer customer = new Customer();
            Address address = new Address();

            // Specify the customer's business address.

            address.Line1 = "1234 Washington Place";
            address.Line2 = "Suite 1210";
            address.City = "Woodinville";
            address.StateOrProvince = "WA";
            address.PostalCode = "98068";
            address.CountryCode = "US";
            customer.CustomerAddress = address;

            customer.Industry = Industry.Other;
            customer.MarketCountry = "US";
            customer.MarketLanguage = LanguageType.English;
            customer.Name = "Alpine Ski House";

            return customer;
        }

        // Populate the User object.
        // This user will have super-admininistrator permissions to manage
        // the customer's data, including the customer's accounts
        // and campaigns in the Bing Ads web application.

        static private User GetUserData()
        {
            User user = new User();
            ContactInfo contact = new ContactInfo();
            Address address = new Address();
            PersonName name = new PersonName();

            // Specify the user's business address.

            address.Line1 = "1234 Washington Place";
            address.Line2 = "Suite 1210";
            address.City = "Woodinville";
            address.StateOrProvince = "WA";
            address.PostalCode = "98068";
            address.CountryCode = "US";
            contact.Address = address;

            // Specifies how to contact the user and where
            // to send correspondence and notifications.

            contact.ContactByPhone = true;
            contact.Phone1 = "(206) 555-0100 ext. 1234";
            contact.Email = "kim@alpineskihouse.com";
            contact.EmailFormat = EmailFormat.Text;

            user.ContactInfo = contact;

            user.CustomerAppScope = ApplicationType.Advertiser;

            // Specify the user's name.

            name.FirstName = "Kim";
            name.LastName = "Abercrombie";
            user.Name = name;

            // Specify the user's log on credentials.

            user.Password = "<PasswordGoesHere>";
            user.SecretQuestion = SecretQuestion.FatherMiddleName;
            user.SecretAnswer = "Michael";
            user.UserName = "kaberc";

            return user;
        }

        // Populate the Account object.
        // Because you are adding an invoice account, you do not have to set
        // the payment method type (the service ignores the value if set).
        // Set the payment method identifier to null; the operation
        // automatically sets the payment method identifier to the identifier
        // of the reseller's invoice.

        static private Account GetAccountData()
        {
            AdvertiserAccount account = new AdvertiserAccount();

            account.CurrencyType = CurrencyType.USDollar;
            account.Name = "Winter Season Sales";
            account.PaymentMethodId = null;

            return account;
        }
    }
}

Community Additions

Show:
© 2014 Microsoft