zulip/templates/zerver/api/update-message.md
2018-01-17 09:27:35 -05:00

2.0 KiB

Update a message

Edit/update the content or topic of a message.

PATCH {{ api_url }}/v1/messages/<msg_id>

<msg_id> in the above URL should be replaced with the ID of the message you wish you update.

Permissions

You only have permission to edit a message if:

  1. You sent it, OR:
  2. This is a topic-only edit for a (no topic) message, OR:
  3. This is a topic-only edit and you are an admin.

Arguments

{generate_api_arguments_table|arguments.json|update-message.md}

Usage examples

  • curl
  • Python
  • JavaScript
curl -X "PATCH" {{ api_url }}/v1/messages/<msg_id> \
    -u BOT_EMAIL_ADDRESS:BOT_API_KEY \
    -d "content=New content"
```python #!/usr/bin/env python

import zulip

Download ~/zuliprc-dev from your dev server

client = zulip.Client(config_file="~/zuliprc-dev")

Edit a message

print(client.update_message({ "message_id": 131, "content": "New content" }))

</div>

<div data-language="javascript" markdown="1">
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
```js
const zulip = require('zulip-js');

// Download zuliprc-dev from your dev server
const config = {
    zuliprc: 'zuliprc-dev',
};

zulip(config).then((client) => {
    // Update a message
    const params = {
        message_id: 131,
        content: 'New Content',
    }

    client.messages.update(params).then(console.log);
});

Response

Example response

A typical successful JSON response may look like:

{
    'msg':'',
    'result':'success'
}

A typical JSON response for when one doesn't have the permission to edit a particular message:

{
    'code':'BAD_REQUEST',
    'result':'error',
    'msg':"You don't have permission to edit this message"
}

{!invalid-api-key-json-response.md!}