/ Platform API
Platform API
    Chat Platform API v3
    Chat Platform API
    Chat Platform API
    Version 3

    Update metacounter

    Copy link

    This action updates existing items of a channel metacounter by their keys or add new items to the metacounter. Metacounter is additional information about a channel that is a collection of of key-value pairs where the value is always an integer.

    Note: See the channel overview page to learn more about differences among data properties.


    HTTP request

    Copy link
    // Update existing items of a channel metacounter by their keys or add new items to the metacounter
    PUT https://api-{application_id}.sendbird.com/v3/{channel_type}/{channel_url}/metacounter
    
    // Update 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

    Copy link

    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. URL encoding a key is recommended.


    Request body

    Copy link

    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

    Copy link

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

    // Updating the values of existing items by their keys and adding a new item to the metacounter.
    {
        "likes": 1,     # 0 + 1 = 1
        "dislikes": 0,
        "giveups": 0,
        "happinesses": 0
    }
    
    // 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 like below is returned. See the error codes section for more details.

    {
        "message": "\"Channel\" not found.",
        "code": 400105,
        "error": true
    }