# storage.setUserStorage
This API must be called from the server. For more information, see Server APIs.
A backend API used to report user data. Mini Games can use this API to report key-value data to users’ CloudStorage.
# Request Address
POST https://api.weixin.qq.com/wxa/set_user_storage?access_token=ACCESS_TOKEN&signature=SIGNATURE&openid=OPENID&sig_method=SIG_METHOD
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
access_token | string | Yes | The credentials used to call the API. | |
openid | string | Yes | The unique identifier of the user. | |
signature | string | Yes | [The signature of the user login status. For more information, see User Login Status Signature Algorithms. | |
sig_method | string | Yes | The hash method for the signature of the user login status, e.g. hmac_sha256. For more information, see User Login Status Signature Algorithms. | |
kv_list | Object | Yes | The data to report. |
kv_list is composed as follows
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
key | string | Yes | The data key. | |
value | string | Yes | The data value. |
# Return Value
# Object
A JSON data package is returned.
Attribute | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | number | Error message |
Valid values of errcode
Value | Description | Minimum Version |
---|---|---|
0 | Request successful | |
-1 | System is busy. Try again later. | |
87016 | Reporting failed because a key-value pair is too long. | |
87017 | Reporting failed because the data volume stored for the user exceeds the limit. | |
87018 | Reporting failed because the number of key-value pairs stored for the user exceeds the limit. | |
87019 | Reporting failed because a key is too long. |
# Sample Code
curl -d '{ "kv_list":[{"key":"score","value":"100"},{"key":"gold","value":"3000"}] }' 'https://api.weixin.qq.com/wxa/set_user_storage?access_token=ACCESS_TOKEN&signature=SIGNATURE&openid=OPENID&sig_method=SIG_METHOD'
# Limits on Hosted Data
If these restrictions are triggered during data reporting, the set data will fail and you will receive a response package with an error code.
- The WeChat users identified by the OpenIds cannot have hosted data in excess of 128 key-value pairs.
- No item in the key-value list can have a key+value length in excess of 1024 bytes.
- No item in the key-value list can have a key length in excess of 128 bytes.