Forum Discussion

cgrinton's avatar
cgrinton
Expert
7 years ago

body (and other?) fields cleared when updating a message to add a label using API v2

I am seeking to add a label to a message using API v2, but am finding that the body field on updated messages is getting cleared by the update. Can somebody help me better understand this behavior, and explain how to make an update like adding a label without changing other details on the message?

Here are details of what I've observed:

Based on the information here I have constructed a call like the following:

curl -X PUT \
    https://[COMMUNITY DOMAIN]/api/2.0/messages/785 \
    -H 'content-type: application/json' \
    -H 'li-api-session-key: [SESSION KEY]' \
    -d '{
            "data":{
                "type":"message",
                "labels":{
"items":[{"type":"label", "text":"my label"}]
} } }'

This successfully adds the label, but also clears the body field on the message. On the other hand, the subject field on the message is not changed. That makes me think an [undocumented] requirement is that when updating a message there are some fields which must be specified  in the HTTP PUT request body with their current values in the HTTP request if they are to be left unmodified, while other fields will retain their current values even if they are not specified.

If anybody can confirm this, and give some hints as to which fields must be specified when updating a message through the API, that would help me greatly! I am worried about updating messages and corrupting/changing existing data without realizing it.

8 Replies

  • cgrinton's avatar
    cgrinton
    Expert
    7 years ago

    Thanks for the pointer VikasB. Using the v1 API (rather than the v2 API) avoids my problems.

    I'd been assuming that v1 was deprecated and not ideal to use for new work, but I think you're teaching me that maybe my assumption has been wrong!

  • luk's avatar
    luk
    Boss
    7 years ago

    I think this should be looked into by the devs/product team, smells like a bug or at least something that should be clarified in the docs, what do you think SuzieH DougS?

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    7 years ago

    luk cgrinton Thank you for bringing this up. This is a regression and the team has created a ticket to get this fixed. In the meantime, use the V1 call mentioned earlier.

  • RhallTalend's avatar
    RhallTalend
    Guide
    6 years ago

    This issue still exists. I am trying to update the body of a message using the v2 API. The body is changed, the labels remain, but the associated image is always dropped. Surely an update should only change what is provided in the body of the message

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    6 years ago

    Thanks RhallTalend Can you tell me what version of Community you're running at the moment?

  • RhallTalend's avatar
    RhallTalend
    Guide
    6 years ago

    I have absolutely no idea how to find this. However, I have found a workaround for the issue by resubmitting the cover_image. I would point out that this was incredibly hard to find out how to do as there are absolutely no examples of doing this. I had to work this out using trial and error. Documentation is sorely lacking. For example, I have just spent five minutes trying to find out how find out what version we are using. Sorry, I'm a little frustrated with how hard it is find out things about this product.