Chat / Platform API
Current version: v3
    Chat Platform API v3
    Chat Platform API
    Chat
    Platform API
    Home
    /
    Chat
    /
    Platform API

    Update metacounter

    Updates the existing items of a channel metacounter by their keys or adds new items to a metacounter.

    Note: See this page to learn more about differences among data properties.


    HTTP request

    // When updating existing items of a channel metacounter by their keys or adding new items to the metacounter
    PUT https://api-{application_id}.sendbird.com/v3/{channel_type}/{channel_url}/metacounter
    
    // When updating a specific item of a channel metacounter by its key
    PUT https://api-{application_id}.sendbird.com/v3/{channel_type}/{channel_url}/metacounter/{key}
    

    Parameters

    The following table lists the parameters that this action supports.

    Parameters
    RequiredTypeDescription

    channel_type

    string

    Specifies the type of a channel. Acceptable values are open_channels and group_channels.

    channel_url

    string

    Specifies the URL of a channel.

    OptionalTypeDescription

    key

    string

    Specifies the key of the metacounter item. If not specified, the items in the metacounter property are updated. If specified, only the item that matches the parameter value is updated. Urlencoding a key is recommended.


    Request body

    The following table lists the properties of an HTTP request that this action supports.

    Properties
    RequiredTypeDescription

    metacounter

    object

    Specifies a JSON object that stores key-value items. The key must not have a comma (,) and its length is limited to 128 characters. The value must be an integer.

    OptionalTypeDescription

    mode

    string

    Specifies how to calculate the item value of the metacounter. Acceptable values are increase, decrease, and set. If set to increase, increments the item value of the metacounter by the value specified in the metacounter property. If set to decrease, decreases the item value of the metacounter by the value specified in the metacounter property. The value of set sets the item value to the precise specified value. (Default: set)

    upsert

    boolean

    Determines whether to add new items in addition to updating existing items. If set to true, new key-value items in the metacounter property are added when there are no items with the keys. If there are already items with the keys, the existing items are updated with the new values. If set to false, only the items with keys that match the ones you specified are updated. (Default: false)

    // When updating the values of existing items by their keys and adding new item to the metacounter
    {
        "metacounter": {
            "likes": 1          // Updated
            "happinesses": 0    // Added
        },
        "mode": "increase",
        "upsert": true
    }
    
    // When updating the value of a specific item by its key
    {
        "value": 2,
        "mode": "increase",
        "upsert": false
    }
    

    Response

    If successful, this action returns the updated or added items in the metacounter in the response body.

    // When updating the values of existing items by their keys and adding new item to the metacounter
    {
        "likes": 1,     # 0 + 1 = 1
        "dislikes": 0,
        "giveups": 0,
        "happinesses": 0
    }
    
    // When updating the value of a specific item by its key
    {
        "likes": 3,     # 1 + 2 = 3
        "dislikes": 0,
        "giveups": 0,
        "happinesses": 0
    }
    

    In the case of an error, an error object is returned. A detailed list of error codes is available here.