# invokeCloudFunction
Call this API at the server side. For more information, see Server API.
Triggers cloud functions. Note: Cloud functions triggered by HTTP API do not contain user information.
# Request Address
POST https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=ACCESS_TOKEN&env=ENV&name=FUNCTION_NAME
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
access_token | string | Yes | Credentials to call API | |
env | string | Yes | ID of the Cloud Base environment | |
name | string | Yes | Cloud function name | |
POSTBODY | string | Yes | The incoming parameter of the cloud function. Its structure is defined by the developer. |
# Return Value
# Object
JSON data package that is returned
Attribute | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | Error message |
resp_data | string | buffer returned by the cloud function |
Valid values of errcode
Value | Description | Minimum Version |
---|---|---|
0 | Request successful | |
-1 | System Error | |
-1000 | System Error | |
40014 | Invalid AccessToken | |
40101 | Required parameter missing | |
41001 | AccessToken missing | |
42001 | AccessToken expired | |
43002 | HTTP METHOD error | |
44002 | Empty POST BODY | |
85088 | Cloud Base is not enabled on this App | |
Other error codes | Cloud Base error codes |
# Sample Code
curl -d '{}' \
'https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=ACCESS_TOKEN&env=ENV&name=login'
# Return Data Example
{
"errcode": 0,
"errmsg": "ok",
"resp_data": "{\"event\":{\"userInfo\":{\"appId\":\"SAMPLE_APPID\"}},\"appid\":\"SAMPLE_APPID\"}"
}
# Tips
- Use this API to trigger the cloud function. In the cloud function, you cannot obtain user information such as OpenID or use other APIs that involve user login status.
- Note that POST BODY is passed to the cloud function as an input parameter.
- Cloud functions triggered by the HTTP API support cloud call.
- The timeout period of the cloud function triggered by the HTTP API is 5s. Please note that the execution time of the cloud function should not be too long.