logo
On this page

Send gifts


Description

Calling this interface to trigger the gift-giving event in the live comment-based game will produce corresponding effects on thelive comment-based game client.

Warning
  • The gift-giving event can only occur after the user joins the game. If the user does not join the game when the gift-giving behavior occurs, the gift-giving event will fail (a few games have special circumstances, please contact technical support to confirm).
  • Please merge the user's gift messages in the room dimension, and then request to this interface. Integrating the user's gift messages every 50-200 ms is recommended.

Request method and endpoint

  • Request method: POST
  • Request URL: https://mini-game-api.zego.im/?Action=SendDanmakuGifts
  • Transmission protocol: HTTPS
  • Call frequency limit: 20 times/second (at the room level)

Request parameters

The following request parameter list only lists interface request parameters. For the public parameter list, please refer to Make API requests.

ParametersTypeIs it requiredDescription
RoomIdStringYesRoom ID, defined by you, can be up to 64 characters long.
MiniGameIdStringYesTo obtain your Game ID, please contact ZEGOCLOUD technical support.
GiftListArray of ObjectYesConsolidated gift list.
UserInfoObjectYesUser information object.
UserIdStringYesUser ID to join the game, defined by you. The maximum length is 48 characters, only numbers and English are allowed.
NicknameStringYesThe user nickname is defined by you. It can be up to 32 characters long.
AvatarStringYesThe address of the user's avatar must be a valid HTTP/HTTPS address and the length must be within 1024 bytes.。
SexStringNoUser gender.
  • 1:Male.
  • 2:Female
GiftInfoObjectYesGift information object.
GiftIdStringYesGift ID. For a specific Gift ID, please contact ZEGOCLOUD technical support.
ValueNumberNoNumber of gifts required for a single effect. Not required, only needed if the gift ID requires different amounts of gifts (value) to trigger different effects.
Please contact ZEGOCLOUD technical support to determine the specific quantity and its relationship to the effect. If not specified, the default value is 1.

Users cannot send an unlimited number of gifts. They must send a specified number of gifts based on the enumeration values predefined in the game rules.

For example, if the game requires 5 gifts of type A to summon a soldier, then when the user sends gifts, the value should be set to 5.

NumNumberYes

Number of desired game effects.

Giftid + Value The corresponding game effects are pre-defined game rules. They are specific to the game. See below for input instructions for GiftId, Value, and Num.

ReceiverIdStringNoUser ID for receiving gifts. This data is needed to record when multiple hosts compete in the same room for PK.
TimestampNumberYesUnix timestamp in milliseconds when the gifting event occurs.
MsgIdStringYesGift Message ID generated by you, representing the message record ID for a single gift. It is used to ensure idempotent consumption of gifts and to query the gifting result. It should be unique for at least 24 hours. Using a duplicate MsgId within 24 hours will return the gifting result of the first occurrence and will not duplicate the gift. The maximum length is 64 characters and supports numbers, English letters, '_' and '-'.

Input instructions for GiftId, Value, and Num

Num (number of game effect units) is related to GiftID (gift) and Value (number of gifts required per unit of effect). It is also influenced by specific game rules. For more details, please contact the ZEGOCLOUD technical support team.

For example, in game A:

  • The GiftId of the "rocket"(a gift) is g1.
  • Sending 10 "rockets" at once will summon a "soldier"(the effect) in the game.
  • Sending 66 "rockets" at once will summon a "general"(the effect) in the game.

During the game, there may be the following situations:

  • When the audience wants to send 20 "rockets" to summon two soldiers in the game, the GiftInfo value passed in at this time is::

    Untitled
    "GiftInfo": {
        "GiftId": "g1",
        "Value": 10,
        "Num": 2
    }
    
    1
    Copied!
  • When the audience wants to send 66 "rockets" to summon a "general" in the game, the value passed in at this time is:

    Untitled
    "GiftInfo": {
        "GiftId": "g1",
        "Value": 66,
        "Num": 1
    }
    
    1
    Copied!
  • If the developer's value does not match what was agreed with the ZEGOCLOUD technical support, an error message will be returned because it does not comply with the agreed game rules.

    Untitled
    "GiftInfo": {
        "GiftId": "g1",
        "Value":30, // 30 is not equal to 10 or 66
        "Num": 1
    }
    
    1
    Copied!

Request example

  • Request URL

    Untitled
    https://mini-game-api.zego.im/?Action=SendDanmakuGifts
    &<Common request parameters>
    
    1
    Copied!
  • Request message body

    Untitled
    {
      "RoomId": "room123",
      "MiniGameId": "TinyLoveWar",
      "GiftList": [
        {
          "UserInfo": {
            "UserId": "user1",
            "Nickname": "test1",
            "Avatar": "http://",
            "Sex": 1
          },
          "GiftInfo": {
            "GiftId": "g1",
            "Value": 5,
            "Num": 2
          },
          "Timestamp": 12312312,
          "ReceiverId":"anchor111",
          "MsgId":"445623452643416236"
      ]
    }
    
    1
    Copied!

Response parameters

ParametersTypeDescription
CodeInt64Error code.
MessageStringDescription of the request result.
RequestIdStringRequest ID.
DataObjectThe specific information returned.
ResultsStringList of gift bullet processing results.
ResultNumberprocess result. 0 indicates success, the rest indicates failure.
MsgStringReason for failure.
MsgIdStringThe unique MsgId of the gift corresponding to the processing result.

There are two scenarios for gift delivery failure:

  • If the error code “code != 0”, it means that all gifts have failed to be delivered. In this case, the MsgId will not be recorded, and you can retry the delivery directly without generating a new MsgId.
  • If the error code “code == 0”, it means that the gift requests have been successfully consumed. However, there may be cases where some gifts are successfully delivered while others fail. The specific information about whether the gifts are successful or the reasons for failure can be found in the Result parameter of the response body. If you need to re-gift a failed gift, you need to regenerate the MsgId.

Response example

Untitled
{
    "Code": 0,
    "Message": "succeed",
    "RequestId": "abcd123",
    "Data": {
        "Results": [
          {
            "Result": 0,
            "Msg": "success",
            "MsgId":"445623452643416236"
          }
        ]
    }
}
1
Copied!

Return code

The following only lists the return codes related to the interface business logic. For complete return codes, please refer to Global return codes.

Return codeDescriptionHandling suggestions
7202001The game was not found, possible reasons include:
  • Incorrect input of MiniGameId.
  • No permission to access this game.
  • Please check if the MiniGameId is correct.
  • Please contact ZEGOCLOUD business personnel to obtain permission for this game.
7202002MiniGameId format error.Please confirm whether the format is String.
7206001The game has not started.Please confirm to send the gift after the game has started.

Result processing result code

Return codeDescriptionHandling suggestions
10003The possible reasons for gift delivery failure include:
  • The user has not joined the game.
  • The room does not exist or has ended.
  • Unknown error.
Please contact ZEGOCLOUD technical staff for troubleshooting.
10004No corresponding gift configured.Please confirm if the gift has been configured.
10005Gift delivery exception.Please contact ZEGOCLOUD technical staff for troubleshooting.
10006The gift request corresponding to MsgId is being processed.Please try again later.

Previous

Send comments

Next

Check gift sending results