Search code examples
blogsibm-connections

How to add tags to a blog post in IBM Connections


How can I add tags to a blog post in IBM Connections? The API documentation says I need to update the blog post with a PUT command. If I do so according to the documentation, then I get a 500 Internal Server error as response. Same happens when trying to create a blog post with a POST command.

Question 1: what is wrong with the command?

Question 2: is there a way to only add tags without updating the content of the blog post?

sUrl = "https://my-connect-server/blogs/%BLOGID%/api/entries/%POSTID%"

sBody = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
        "<entry xmlns=""http://www.w3.org/2005/Atom"">" & _
        "<id>urn:lsid:ibm.com:blogs:entry-%POSTID%</id>" & _
        "<title type=""text"">Test Blog Post</title>" & _
        "<summary type=""html"">new summary</summary>" & _
        "<content type=""html"">new content </content>" & _
        "<category term=""new-tag-1""></category>" & _
        "<category term=""new-tag-2""></category>" & _
        "<entry>"

Call oHttp.Open("PUT", sUrl, False)
Call oHttp.setRequestHeader("Content-Type", "application/atom+xml")
Call oHttp.send(sBody)

Solution

  • The reason is you are not sending a full payload to the blog api. You should send back the full Blog entry with the additions/subtractions you want to make to the XML payload.

    I call the api https://<SERVER>/blogs/5133e363-7456-4525-afe6-188960888b35/api/entries/b17182a4-7807-4adf-97c7-8ac051a3f115

    I had to trim off the XML header, so it's like this:

    <entry xml:lang="en" dir="ltr" xmlns="http://www.w3.org/2005/Atom">
          <id>urn:lsid:ibm.com:blogs:entry-b17182a4-7807-4adf-97c7-8ac051a3f115</id>
          <snx:communityUuid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">5133e363-7456-4525-afe6-188960888b35</snx:communityUuid>
          <link href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/entries/b17182a4-7807-4adf-97c7-8ac051a3f115" rel="edit" type="application/atom+xml">
          </link>
          <link href="https://<SERVER>/blogs/5133e363-7456-4525-afe6-188960888b35/entry/Test" rel="alternate" type="text/html">
          </link>
          <link href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/feed/entrycomments/Test/atom" rel="replies" type="application/atom+xml" thr:count="0" xmlns:thr="http://purl.org/syndication/thread/1.0">
          </link>
          <app:collection href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/recommend/entries/b17182a4-7807-4adf-97c7-8ac051a3f115" xmlns:app="http://www.w3.org/2007/app">
            <atom:title xmlns:atom="http://www.w3.org/2005/Atom">Likes</atom:title>
            <atom:category term="recommend" scheme="http://www.ibm.com/xmlns/prod/sn/collection" xmlns:atom="http://www.w3.org/2005/Atom">
            </atom:category>
            <app:categories fixed="yes">
            </app:categories>
          </app:collection>
          <app:collection href="https://<SERVER>:443/blogs/5133e363-7456-4525-afe6-188960888b35/api/entrycomments/b17182a4-7807-4adf-97c7-8ac051a3f115" xmlns:app="http://www.w3.org/2007/app">
            <atom:title xmlns:atom="http://www.w3.org/2005/Atom">Comment Entries</atom:title>
            <app:accept>application/atom+xml;type=entry</app:accept>
            <atom:category term="comments" scheme="http://www.ibm.com/xmlns/prod/sn/collection" xmlns:atom="http://www.w3.org/2005/Atom">
            </atom:category>
            <app:categories fixed="yes">
            </app:categories>
          </app:collection>
          <snx:moderation status="approved" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
          </snx:moderation>
          <title type="text">Test</title>
          <updated>2015-08-14T11:58:05.000Z</updated>
          <app:edited xmlns:app="http://www.w3.org/2007/app">2015-08-14T11:58:05.000Z</app:edited>
          <published>2015-08-14T11:57:44.000Z</published>
          <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/recommendations" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">0</snx:rank>
          <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/comment" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">0</snx:rank>
          <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/hit" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">8</snx:rank>
          <author>
            <name>John Doe0</name>
            <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">20000395</snx:userid>
            <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
            <snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
          </author>
          <contributor>
            <name>John Doe0</name>
            <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">20000395</snx:userid>
            <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
            <snx:isExternal xmlns:snx="http://www.ibm.com/xmlns/prod/sn">false</snx:isExternal>
          </contributor>
          <category term="test">
          </category>
     <category term="test2">
          </category>
          <app:control xmlns:app="http://www.w3.org/2007/app">
            <app:draft>no</app:draft>
            <snx:comments enabled="yes" days="0" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
            </snx:comments>
          </app:control>
          <summary type="html">&lt;p dir="ltr"&gt;Test&lt;/p&gt;</summary>
          <content type="html">&lt;p dir="ltr"&gt;Test&lt;/p&gt;</content>
        </entry>
    

    I added to the category tag before

    <category term="test2">
          </category>
    

    I send a put to the same api as above, with header Content-Type: application/atom+xml and Method: PUT

    You should get Status Code: 200 OK