Follow the steps in this quickstart guide, and in about 10 minutes you'll have a simple .NET C# console app that makes requests to the zero-touch enrollment reseller API.
Prerequisites
To run this quickstart, you'll need:
- A Google account, that's a member of your zero-touch enrollment reseller account. If you haven't onboarded yet, follow the steps in Get started in the Reseller portal guide.
- Visual Studio 2013 or later.
- Access to the internet and a web browser.
Step 1: Turn on the zero-touch enrollment API
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials .
- Set What data will you be accessing? to Application data.
- Click Next. You should be prompted to create a service account.
- Give a descriptive name for Service account name.
- Note the Service account ID (it looks like an email address) because you'll use it later.
- Set Role to Service Accounts > Service Account User.
- Click Done to finish creating the service account.
- Click the email address for the service account that you created.
- Click **Keys**.
- Click **Add key**, then click **Create new key**.
- For **Key type**, select **JSON**.
- Click Create and the private key downloads to your computer.
- Click **Close**.
- Move the file to your working directory and rename it
service_account_key.json
.
Step 2: Link the service account
- Open the zero-touch enrollment portal. You might need to sign in.
- Click Service accounts.
- Click Link service account.
- Set Email address to the address of the service account you created.
- Click Link service account to use the service account with your zero-touch enrollment account.
Step 3: Prepare the project
- Create a new .NET Core C# Console Application project in Visual Studio.
- Open the Package Manager, select the package source nuget.org, and add
the following packages:
Google.Apis.AndroidProvisioningPartner.v1
Google.Apis.Auth
To learn more, read the Microsoft document Install and use a package.
Step 4: Set up the sample
- Drag
service_account_key.json
(downloaded in Step 1) into your Visual Studio Solution Explorer. - Select
service_account_key.json
, and then go to the Properties window and set Copy to output directory field to Always copy. - Replace the contents of
Program.cs
with the following code. - Insert your own reseller partner ID as the value for
PartnerId
(the app's first line).
using Google.Apis.AndroidProvisioningPartner.v1; using Google.Apis.AndroidProvisioningPartner.v1.Data; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; using System; using System.Collections.Generic; using System.IO; namespace ZeroTouchResellerQuickstart { class Program { // TODO: replace this with your partner reseller ID. static long PartnerId = 11036885; // Use a single scope for the all methods in the reseller API. static readonly string[] Scopes = { "https://www.googleapis.com/auth/androidworkprovisioning" }; static string ApplicationName = "Zero-touch Reseller .NET Quickstart"; static void Main(string[] args) { // Create a credential to authorize API requests using a service account key. // The service account must be linked using the zero-touch portal. ServiceAccountCredential credential; using (var stream = new FileStream("service_account_key.json", FileMode.Open, FileAccess.Read)) { credential = GoogleCredential.FromStream(stream) .CreateScoped(Scopes) .UnderlyingCredential as ServiceAccountCredential; } // Create a zero-touch enrollment API service endpoint. var service = new AndroidProvisioningPartnerService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = ApplicationName }); // Send an API request to list all our customers. PartnersResource.CustomersResource.ListRequest request = service.Partners.Customers.List(PartnerId); ListCustomersResponse response = request.Execute(); // Print out the details of each customer. IList<Company> customers = response.Customers; if (customers != null) { foreach (Company customer in customers) { Console.WriteLine("Name:{0} ID:{1}", customer.CompanyName, customer.CompanyId); } } else { Console.WriteLine("No customers found"); } } } }
Partner ID
API calls typically need your reseller partner ID as an argument. To find your partner ID from the zero-touch enrollment portal, follow the steps below:
- Open the portal. You might need to sign in.
- Click Service accounts.
- Copy your partner ID number from the Your reseller ID line.
Step 5: Run the sample
To build and run the sample, click
Start in the Visual Studio toolbar.Troubleshooting
Tell us what went wrong with the quickstart and we'll work to fix it. To learn how zero-touch uses service accounts to authorize API calls, read Authorization.