Help Center/ Huawei Cloud Astro Zero/ API Reference/ APIs/ Data Modules/ Batch Adding or Updating Object Data
Updated on 2025-05-13 GMT+08:00

Batch Adding or Updating Object Data

Function

This API is used to add or update data records in batches. If the request contains id, it is used to update data. If the request does not contain id, it is used to add data.

URI

POST Huawei Cloud Astro Zero domain name/u-route/baas/data/v1.0/upsert/{objectName}

Table 1 URI parameter

Parameter

Mandatory

Type

Description

objectName

Yes

String

Explanation

Data object name. For details, see Logging In to the Application Designer. You can access the application designer and choose Data > Object to view data object names.

Constraints

None

Value

1–80 characters

Default value

None

Request Parameters

Table 2 Request parameter

Parameter

Mandatory

Type

Description

records

Yes

Array

Explanation

Array of the data to be added or updated.

Constraints

If the parameter value contains id, the request is used to update data. Otherwise, the request is used to add data.

Response Parameters

Table 3 Response parameters

Parameter

Type

Description

resCode

String

Explanation

Return code.

Value

If the request is successful, 0 is returned. For details about other error codes, see Error Codes.

resMsg

String

Explanation

Message returned.

Value

If the request is successful, "Success" is returned. In other cases, an error message is returned.

result

Array

Explanation

If the request is successful, an array of record IDs is returned.

Example Request

To add three data records into the TestProject__testForObject1__CST object, send the following request, in which the body contains the records to be added:
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/data/v1.0/upsert/TestProject__testForObject1__CST
  
 {
    "records":[
     {
         "name":"zhang",
         "TestProject__length__CST":"17"
     },
     {
         "name":"li",
         "TestProject__length__CST":"30"
     },
     {
         "name":"wang",
         "TestProject__length__CST":"20"
     }
     ]
}

Example Response

{
    "resCode": "0",
    "resMsg": "Success",
    "result": [
        {
            "id": "cglE000000aMFjB9ipAu"
        },
        {
            "id": "cglE000000aMFjB9ipAv"
        },
        {
            "id": "cglE000000aMFjB9ipAw"
        }
    ]
}

Status Code

See Status Codes.

Error Code

See Error Codes.