Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
Huawei Cloud Astro Canvas
Huawei Cloud Astro Zero
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Calling RESTful APIs with a RESTful Service

Updated on 2025-03-24 GMT+08:00

You can configure a RESTful service so Astro Zero can call the RESTful APIs provided by third-party systems. A RESTful service is a group of modularized RESTful APIs (RESTful actions). Once the connection is established, you can add actions to transform third-party APIs into a format recognizable by Huawei Cloud Astro Zero. This allows Huawei Cloud Astro Zero to call the APIs effectively.

Creating a Custom Connector to Interconnect with a RESTful Service

You can configure a custom link to connect to a RESTful service and incorporate actions that enable the system to call the RESTful APIs from a third-party system, thereby utilizing the services provided by that third-party system.

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Integrations.
  3. In the Connectors area, click Connector Instance.
  4. In the Type area, select Custom Connector.
  5. Click +, configure connector information, and click Save.

    Figure 1 Creating a custom connector
    Table 1 Parameters for creating a custom connector

    Parameter

    Description

    Label

    Custom connector label, which can be modified after being created.

    Value: 1–64 characters.

    Name

    Custom connector name, which uniquely identifies the connector in the system and cannot be changed after the connector is created. The naming requirements are as follows:

    • The value cannot exceed 64 characters, including the prefix namespace.

      To prevent duplicate data names among different tenants, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.

    • Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).

    Logo

    Custom connector logo. You can upload an image from the local host.

    Description

    Enter the description of the custom connector.

    Value: 1–255 characters.

  6. On the Authentication Information tab page, click New.
  7. Set authentication information and click Save.

    You can create multiple authentications. Different actions can have different authentication modes.

    Figure 2 Setting basic authentication information
    Figure 3 Configuring authentication
    Table 2 Authentication information parameters

    Parameter

    Description

    Label

    Authentication label, which is displayed on the page.

    Value: 1–64 characters.

    Name

    Authentication name, which uniquely identifies the authentication in the system. The naming requirements are as follows:

    • The value cannot exceed 64 characters, including the prefix namespace.

      To prevent duplicate data names among different tenants in Huawei Cloud Astro Zero, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.

    • Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).

    Category

    Category to which the authentication belongs. Select a value from the drop-down list.

    Description

    Enter the authentication description as required.

    Value: 1–255 characters.

    Use Certificate

    Whether the client certificate is required on the server and whether bidirectional authentication is required. If this parameter is selected, you need to configure the Type, Certificate, and Key.

    Use Root Certificate

    Whether the server certificate is required on the client and whether bidirectional authentication is required.

    If this parameter is selected, you need to enable root certificate verification in the management center and upload the root certificate. For details, see Enabling Root Certificate Authentication for Server Identity Verification. After the upload, select the corresponding certificate from the Root Certificate drop-down list.

    API Host Address

    After this parameter is configured, only RESTful operation requests whose request URL starts with the specified address will be allowed. This prevents leakage of sensitive information. Each time the address is changed, the authentication information needs to be reconfigured.

    Package Current Configuration

    If this parameter is selected, the connector will be packed together with applications. For example, if an application package is released to the runtime environment, the current configuration is synchronized to the runtime environment by default. This parameter is selected by default. You are advised not to select this option in information-sensitive scenarios.

    Authentication Settings

    • Authentication protocol: Options are OAuth, Simple headers, and JWT.
    • Authentication mode: Set it to client credentials. Only client credentials of OAuth 2.0 are supported.
    • Authentication address: Address for a third-party system to obtain the token through the OAuth 2.0 protocol. An example address to obtain a token is https://{host}:{port}/baas/auth/v1.0/oauth2/token.
    • Client ID: Client ID in the OAuth 2.0 protocol. If the RESTful service is provided by Astro Zero, perform the following steps to view the RESTful service:
      1. Access the Astro Zero environment configuration page.
      2. In the navigation pane, choose Integrated Connection > OAuth.
      3. In the OAuth authentication list, view the client ID corresponding to the authentication.
    • Client secret: Client secret in the OAuth 2.0 protocol. If the RESTful service is provided by Astro Zero, perform the following steps to view the RESTful service:
      1. The Huawei Cloud Astro Zero environment configuration page is displayed.
      2. In the navigation pane, choose Integrated Connection > OAuth.
      3. In the OAuth authentication list, click of the corresponding authentication.
      4. In the displayed dialog box, click OK to download the key file to the local PC.

        client_secret in the key file is the value of Client Secret.

    • Body Property: Mapping rules for message fields returned from authentication APIs.

      Figure 4 describes the response body based on the OAuth2 standard protocol. The key returned by some third-party APIs may not be the standard key. For example, some third-party APIs will return accessToken instead of access_token used in Astro Zero. Therefore, you need to configure the mapping between the keys.

      The message body property configured in Figure 3 is accessToken returned by a third-party system. Huawei Cloud Astro Zero uses the access_token key value to store the message body property. The final storage result is as follows:

      {
      "access_token": ${accessToken}
      }
    • Header Property: Mapping rules for message headers in requests to service APIs.

      According to OAuth 2.0, the token is put in the request header: Authorization: Bearer ${access_token}.

      However, some APIs do not comply with this rule. For example, for an API used to access the platform, the token is put in the request header Access-Token and does not need the prefix Bearer.

      The message header property configured in Figure 3 indicates that you need to obtain the value of access_token from the message body and put the value in the request header Access-Token.

    Figure 4 Response body

Creating and Enabling a RESTful Action

After the RESTful service is interconnected, you can incorporate actions that enable the system to call the RESTful APIs from a third-party system, thereby utilizing the services provided by that third-party system.

  1. Click the RESTful service created in Creating a Custom Connector to Interconnect with a RESTful Service. On the Action tab page, click New.
  2. After setting the information, click the next button.

    Figure 5 Parameters for creating an action
    Table 3 Parameters for creating an action

    Parameter

    Description

    Label

    Action label, which is displayed on the page.

    Value: 1–64 characters.

    Name

    Action name, which uniquely identifies the action in the system. The naming requirements are as follows:

    • The value cannot exceed 64 characters, including the prefix namespace.

      To prevent duplicate data names among different tenants, each tenant must define a unique namespace when first creating an application. A tenant can create only one namespace. After being created, the namespace cannot be modified.

    • Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).

    URL

    URL of the RESTful service provided by the third-party system. For example, /path/test (the host address needs to be configured for authentication information), http://www.domain name .com, or http://system parameter.

    Method

    Select a method from the drop-down list.
    • GET: obtains resources.
    • POST: creates resources.
    • PUT: updates resources.
    • PATCH: updates parts of resources.
    • DELETE: deletes resources.
    • OPTIONS: obtains the method supported by the current URL.

    When Method is set to PUT or POST, you can customize input parameters of the message body. If the input parameters are of the array or non-JSON type, set them to the key-value format. When you select Key-Value for Message body format, a common variable $in, will be introduced. Array or non-JSON variables will be saved to $in, converted to the key-value format, and passed to the RESTful action.

    Content Type

    The value depends on the content type supported by the third-party system and is defined in HTTP.

    • application/json
    • application/x-www-form-urlencoded
    • application/xml
    • multipart/form-data
    • text/html
    • text/plain

    Return Type

    If the value is application/json, the content-type configured by the third-party system rather than that returned by it will be used to parse the returned content.

    If this parameter is left blank, content-type returned in the HTTP response will be used to parse the content.

    Timeout

    If the third-party system does not return any result within the specified period, an error will be reported.

    Unit: second.

    Date Format

    If the input parameters of the RESTful service include a parameter of the Date type in a specified format, this parameter is mandatory.

    Ensure that the input parameters provided by Astro Zero meet the third-party requirements. For example, if the RESTful service has an input parameter of the Date type and the format is YYYY-MM-DD, set this parameter to YYYY-MM-DD.

    Date/Time Format

    If the input parameters of the RESTful service include a parameter of the DateTime type in a specified format, this parameter is mandatory.

    Ensure that the input parameters provided by Huawei Cloud Astro Zero meet the third-party requirements. For example, if the RESTful service has an input parameter of the DateTime type and the format is YYYY-MM-DD hh:mm:ss, set this parameter to YYYY-MM-DD hh:mm:ss.

    Disable Request Header Normalization

    Whether to disable request header normalization. If this parameter is selected, 'accept-language' will not be normalized to 'Access-Language'.

    This parameter is deselected by default.

    Disable HTML Character Escaping

    Whether to disable HTML character escaping in the JSON request body, such as & and <>. If this parameter is selected, '&' will not be escaped to '\u0026'.

    This parameter is deselected by default.

    Description

    Enter the action description as required.

    Value: 1–255 characters.

  3. Configure the header input parameter and click Next.

    If this API does not have header input parameters, delete the first row. If there are multiple header input parameters, click . If the header parameters have been defined during creation of the RESTful service, click Insert From Template and modify the template.
    Figure 6 Header input parameter configuration page
    Table 4 Parameters on the header input parameter configuration page

    Parameter

    Description

    Label

    Label of a message header input parameter, which is displayed on the page.

    Name

    Unique name of a header input parameter.

    Data Type

    Data type of a header input parameter. The options are as follows:
    • Number
    • String
    • Boolean
    • Sensitive Text

    Default Value

    Default value of the header input parameter. You can customize the value only after selecting Default.

    Description

    Enter the description of the input parameter.

    Default

    Indicates whether the input parameter of the header has a default value. If this parameter is selected, you can customize the value in Default Value. If Data Type is set to Sensitive Text, the default value cannot be set.

    Required

    Indicates whether the input parameter of the header is mandatory.

    Operation

    Click or to copy or delete the header input parameter.

  4. Configure the input parameter and click Next.

    If this API does not have input parameters, you do not need to set the parameters. Delete the first row. If there are multiple input parameters, click and define basic information about the input parameters.

    Message body format in the upper right corner of the page is displayed only when Method is set to PUT or POST. If the third-party input parameter is of the array or non-JSON type, set Message body format to Value.

    For example, if Message body format is set to Key-Value and input parameters A, B, and C are defined, the request message body will pass {A:1, B:2, C:3}, and the request receiver will receive {A:1, B:2, C:3}. If Message body format is set to Value, $in will be introduced. The request message body will pass {$in: [1,2,3]}, and the request receiver will receive [1,2,3].

    Figure 7 Page for configuring the input parameter
    Table 5 Input parameter description

    Parameter

    Description

    Label

    Label of an input parameter, which is displayed on the page.

    Name

    Name of an input parameter, which uniquely identifies the input parameter in the system.

    Placement

    Position of the input parameter. The options are as follows:

    • Body
    • URL Query
    • URL Path

    Data Type

    Data type of the input parameter. The options are as follows:
    • Date: accurate to days.
    • Date Time: accurate to seconds.
    • Number: The value is a number.
    • String
    • Boolean: Only two values are allowed, for example, true and false.
    • External Struct
    • Map
    • Object: Object identifier type.
    • Sensitive Text: Such as name or mobile number.

    Namespace

    If DataType is set to External Struct, you need to set the namespace to which the input parameter belongs.

    Metadata Name

    When the data type is set to object, you need to select the metadata name, that is, the custom object created in the application.

    Default Value

    Sets the default value of an input parameter.

    Description

    Enter the description of the input parameter.

    Value: 1–255 characters.

    Default

    Indicates whether an input parameter has a default value. If this parameter is selected, you can customize the value in Default Value. If DataType is set to Sensitive Text, the default value cannot be set.

    Required

    Indicates whether an input parameter is mandatory.

    Collection

    Whether the input parameter is set to the array type.

    Operation

    Click or to copy or delete the input parameter.

  5. Configure output parameters and click the save button.

    If this API does not have output parameters, you do not need to set the parameters. Delete the first row. If there are multiple output parameters, click and define basic information about the output parameters.

    When you select Value for Message body format, a common variable $out, will be introduced. The body content will be saved to $out as output parameters.

    For example, if Message body format is set to Key-Value and output parameters A, B, and C are defined, the response message body will pass {A:1, B:2, C:3}, and the request sender will receive {A:1, B:2, C:3}. If Message body format is set to Value, $out will be introduced. The response message body will pass [1,2,3], and the request sender will receive {$out: [1,2,3]}.

    Figure 8 Page for configuring output parameters
    Table 6 Parameters for configuring output parameters

    Parameter

    Description

    Label

    Label of an output parameter, which is displayed on the page.

    Name

    Name of an output parameter, which uniquely identifies the output parameter in the system.

    Placement

    Position of the output parameter. The options are as follows:

    • Header
    • Body

    Data Type

    Data type of the output parameter. The options are as follows:
    • Date: The value is accurate to day.
    • Date/Time: time type, accurate to second.
    • Number: The value is a number.
    • Character string: The value is a character string.
    • Boolean: The value is true or false.
    • Global structure
    • Key-value pair (Map): Map collection type.
    • Object: Object identifier type.

    Namespace

    If the data type is set to global structure, you need to set the namespace to which the parameter belongs.

    Metadata Name

    When the data type is set to object, you need to select the metadata name, that is, the custom object created in the application.

    Description

    Description of the parameter.

    Collection

    Whether the input parameter is set to the array type.

    Operation

    Click or to copy or delete the parameter.

  6. On the Action tab page, click in the row where the RESTful action is located to enable the RESTful action.

    You can click Export to export a ZIP package that contains all RESTful APIs of the service. You can click Import to import a YAML file to import RESTful actions.

Using a Flow to Call an Action

Create a flow. Then, use the flow to call the actions added to the RESTful service to integrate the service functions provided by the third party into Astro Zero.

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Logic.
  3. Click next to Flow. On the displayed dialog box, specify the flow label and name and click Add.

    Figure 9 Adding a flow

  4. In the navigation pane of the flow designer page, choose Connector > Custom > Service name, and drag the RESTful service icon created in 2 to the canvas.
  5. Set the parameters for calling an action.

    Figure 10 Configuring an action
    Table 7 Parameters for calling an action

    Parameter

    Description

    Action

    Select the action created in Creating and Enabling a RESTful Action.

    Input Parameters

    Click Add Row to set input parameters.

    In Target, select the input parameter set in 4 and set the corresponding value in Source.

    Output Parameters

    Click Add Row to set output parameters.

    In Target, select the output parameter set in 5 and set the corresponding value in Source.

  6. Click in the upper part of the flow designer page to save the flow.
  7. Click to activate the flow.
  8. In the input parameter area, enter the request parameters, click Run, and view the output result.

Using a Script to Call an Action

Create a script. Then, use the script to call the actions added to the RESTful service to integrate the service functions provided by the third party into Huawei Cloud Astro Zero.

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Logic.
  3. Click next to Script. On the displayed dialog box, specify the script name, and click Add.

    Figure 11 Adding an empty script

  4. In the script editor, enter the following code:

    // Here's your code.
    import * as connector from "connector";
    let client = connector.newClient("Namespace__Rest1", "Namespace__test1");
    let result = client.invoke("Namespace__flapRefund", {});
    console.log(result) 

    Namespace __ Rest1 indicates the connector name, Namespace__test1 indicates the name of the authentication information configured in Creating a Custom Connector to Interconnect with a RESTful Service, and Namespace __flapRefund indicates the action name configured in Creating and Enabling a RESTful Action.

    If input parameters are set in the connector, define a input2 in the script. The following is an example script:

    // Here's your code.
    import * as connector from "connector";
    let client = connector.newClient("Namespace__Rest1", "Namespace__test1");
    let input2 = { "Parameter name": "Parameter value" }
    let result = client.invoke("Namespace__flapRefund", {});
    console.log(result)

  5. Click in the upper part of the script editor to save the script.
  6. After the script is saved, click to run the script.
  7. On the input parameter tab page at the bottom of the page, enter request parameters and click in the upper right corner of the test window.
  8. On the log tab page, view the printed logs.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback