[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Let’s say that you need to create an in-app product on Huawei AppGallery Connect. To do this, you sign in to AppGallery Connect, browse to your application, go to In-App Purchase, specify product information, and release the product. However, in reality, an application never have one but ten or twenty in-app products instead. In other words, you have to repeat the boring procedure mentioned above ten or twenty times! Don’t panic yet. This article will show you how to automate such mundane work using Product Management Service API.

The Product Management Service (PMS) API is a part of AppGallery Connect API, a HUAWEI’s alternative to Google Play Developer API. It provides RESTful APIs that can be used to create and update in-app product and promotion information. Utilizing this API, the automation tool (in Java) provided in this article will help you manage in-app product fast and precisely. Let’s examine how this tool works and its features.

Creating an API client

Accessing PMS API, as well as any other Connect APIs, requires authorization from the AppGallery Connect server in advance using either of the following modes:

API client mode: In this mode, an API client is used to authenticate and get access to AppGallery Connect APIs

OAuth client mode: In this mode, access to AppGallery Connect APIs is authorized by Huawei developer accounts. This mode is appropriate for developing a third-party IDE or development tool that needs to be connected to AppGallery Connect. This mode will not be discussed in this article

The tool I created utilized API client mode to call the AppGallery Connect API. Therefore, to be able to use the tool, you need an API client. The procedure of creating an API client is as follows:

Sign in AppGallery Connect and select Users and Permissions

Go to API Key > Connect API from the navigation tree on the left and click Create.

Set Name to a customized client name, set Roles to the corresponding role, and click Confirm. For details about roles and permissions, please refer to Roles and Permissions

After the client is successfully created, record the values of Client ID and Key in the client information list. You will need these values to run the tool later.

How to use the automation tool?

The automation tool is a Maven project, developed in Eclipse IDE. You will need to download and install Eclispe IDE for Java Developers (https://www.eclipse.org/downloads/packages/release/2020-06/r/eclipse-ide-java-developers) if you haven’t already. Then, download the tool from the github repos (https://github.com/buiquanghuy23103/PMS-demo). Once you had the tool and the IDE, let’s run it by following the instructions below:

Open Eclipse IDE. Go to File > Import > Maven > Existing Maven Projects. Then click Next.

Browse to the directory of the sample project

Select pom.xml in the Projects box and click Finish.

Open Package Explorer (Window > Show View > Package Explorer) and navigate to src > test > PmsApiDemo.java. In this file, provide Client ID, Client Key and App ID

To run the tool, from the app bar of Eclipse IDE, go to Run > Run

Creating a product

You can create new in-app products in few seconds with PMS. Go to projectDirectory > src > test > CreateProducts.java to specify product information, and then call CreateProducts.createNewProducts() in PmsApiDemo.java. Please note that product information has to follow the rules in ProductImportInfo. Otherwise, the tool will throw an exception.

public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
String token = GetToken.getToken(domain, clientId, clientSecret);
CreateProducts.createNewProducts(domain, clientId, token, appId);
}

Get product information

You can easily view information of any in-app products in AppGallery Connect through PMS. All you need to do is calling GetIapProductInfo.getProductInfoDetail() in PmsApiDemo.java.

public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
String token = GetToken.getToken(domain, clientId, clientSecret);
GetIapProductInfo.getProductInfoDetail(domain, clientId, token, appId, productNo);
}

The response will be in JSON format as follow:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/105/303/0890358000024105303.20200715124040.82420879820577691887026374818383:50510724021707:2800:0E1A3F85C360B40C4ED449A84EF955FABFDB3C294DF02CC21F97E6270D41A238.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/105/303/0890358000024105303.20200715124040.82420879820577691887026374818383:50510724021707:2800:0E1A3F85C360B40C4ED449A84EF955FABFDB3C294DF02CC21F97E6270D41A238.jpg[/IMG]

Update product information

You can also update product information in the AppGallery through PMS. Go to UpdateProduct. generateUpdateRequest() to update your product information, and then call UpdateProduct.update() in PmsApiDemo.java.

public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
String token = GetToken.getToken(domain, clientId, clientSecret);
UpdateProduct.update(domain, clientId, token, appId, productNo);
}

Apart from these endpoints I integrate, you can also check out the other features of the PMS API here:

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agcapi-pms-api-manage_product_promotion