OpenNTF / SocialSDK

IBM Social Business Toolkit SDK
https://developer.ibm.com/social
53 stars 70 forks source link

BaseService.createData returns Bad Request (400) , want to create a Bookmark programmatically #1742

Closed SiriSch closed 8 years ago

SiriSch commented 8 years ago

Hey Paul,

I would like to create standalone bookmarks and bookmarks in communities programmatically.

To create a bookmark in a community I tried the following code:

 public static void testcreateData() throws ClientServicesException {

    String communityUuid = "e8d9c8e7-b735-4765-be0b-c6073705af7a";

    String myUserid = Variables.aProfileService.getMyUserId();

    String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<entry" + "xmlns:atom=\"http://www.w3.org/2005/Atom\""
      + "xmlns:snx=\"http://www.ibm.com/xmlns/prod/sn\"" + "xmlns:thr=\"http://purl.org/syndication/thread/1.0\">"
      + "<category term=\"bookmark\" scheme=\"http://www.ibm.com/xmlns/prod/sn/type\">" + "</category>"
      + "<id>http://communities.ibm.com:2006/service/atom/community/bookmarks?communityUuid=" + communityUuid
      + "&amp;referenceId=" + myUserid + "</id>" + "<title type=\"text\">IBM Bookmark Test NEW</title>"
      + "<summary type=\"text\">IBM Description NEW</summary>" + "<content type=\"text\">IBM Description NEW</content>"
      + "<published>2015-12-08T14:32:11.547Z</published>" + "<updated>2015-12-08T14:32:11.547Z/updated>"
      + "<category term=\"ibm\">" + "</category>" + "<category term=\"sbt\">" + "</category>"
      + "<link href=\"http://www.ibm.com/\">" + "</link>"
      + "<link href=\"https://greenhousestage.lotus.com/communities/service/atom/community/bookmarks?communityUuid="
      + communityUuid + "&amp;referenceId=" + myUserid + "\" rel=\"self\">" + "</link>"
      + "<link href=\"https://greenhousestage.lotus.com/communities/service/atom/community/bookmarks?communityUuid="
      + communityUuid + "&amp;referenceId=" + myUserid + "\" rel=\"edit\">" + "</link>" + "</entry>";
    String serviceUrL = Variables.baseURL + "/dogear/api/app";
    Variables.aBookMarkService.createData( serviceUrL, null, content );

  }

Our host is censored.

My concatenated Contentstring is the following:

<?xml version="1.0" encoding="UTF-8"?><entryxmlns:atom="http://www.w3.org/2005/Atom"xmlns:snx="http://www.ibm.com/xmlns/prod/sn"xmlns:thr="http://purl.org/syndication/thread/1.0"><category term="bookmark" scheme="http://www.ibm.com/xmlns/prod/sn/type"></category><id>http://communities.ibm.com:2006/service/atom/community/bookmarks?communityUuid=e8d9c8e7-b735-4765-be0b-c6073705af7a&amp;referenceId=8E825631-A6E4-4D1C-9360-76E7F588EC2F</id><title type="text">IBM Bookmark Test NEW</title><summary type="text">IBM Description NEW</summary><content type="text">IBM Description NEW</content><published>2015-12-08T14:32:11.547Z</published><updated>2015-12-08T14:32:11.547Z/updated><category term="ibm"></category><category term="sbt"></category><link href="http://www.ibm.com/"></link><link href="https://greenhousestage.lotus.com/communities/service/atom/community/bookmarks?communityUuid=e8d9c8e7-b735-4765-be0b-c6073705af7a&amp;referenceId=8E825631-A6E4-4D1C-9360-76E7F588EC2F" rel="self"></link><link href="https://greenhousestage.lotus.com/communities/service/atom/community/bookmarks?communityUuid=e8d9c8e7-b735-4765-be0b-c6073705af7a&amp;referenceId=8E825631-A6E4-4D1C-9360-76E7F588EC2F" rel="edit"></link></entry>

I get the following error:


Request to url https://ourhost.com/dogear/api/app returned an error response 400:Bad Request HTTP/1.1 400 Bad Request [Date: Tue, 08 Dec 2015 11:55:40 GMT, X-Frame-Options: SAMEORIGIN, Strict-Transport-Security: max-age=max-age=31536000;includeSubDomains, X-XSS-Protection: 1;mode=block, X-Permitted-Cross-Domain-Policies: master-only, X-Powered-By: Servlet/3.0, X-LConn-Auth: false, X-UA-Compatible: IE=9,8, Expires: Thu, 1 Jan 1970 00:00:00 GMT, Cache-Control: no-store, no-cache, must-revalidate, $WSEP: , Set-Cookie: LtpaToken2=Fnd4yYmsvwQ9vDrlh8R7JD3KQnHwNw9NbG9BZS1Q0NWp1ptmMSjt8RWzgPDJisuwEc3YsHZ7wjqsBihKftbto1FRFNL7gSzGPyO1iUm2CD7d+ndYU0hVuKadwWKYU6KzTGc5Dl5FLzPwG79qLv2lt9//E5+a7FN1IRpDJ3Y3/kQCgH8yfn+pdwrBxLEGAAjdgqo5+VoOAo+ToMLYPI/X/kYjiJm9UnIPHvelNds0r17TNVZX+45LmSN3tbduIPPXWfQkr97ponUKAMGm4FF7hERm8Wdux6gFDylla0LHrBljXjBUfEveUuexOZhp4OR9red7uumr3H3hpOeBG2xj/P30e4In4qPnGGC+UT/3CMakmmA8GMBPOZ6DO94EYqzTa9qzGWC9FCT8mf4sqUNq2bi1V3z+aMLpjYzBRPK6tyN/xxOXo2luyQlZTuCynp4NTk1IdTUbxxS3RBqb6KVDHihcO3RaWzh7B9+Scb/JuCTuRLF/52cJAdrdHa9z5AKYf+8hF5kt0Osu2qZW7w2/svKc+xIKio2/LWDvSe15HxN6tqJ7uy2ySfMpQy968Bus/Dne4b35Fr4CNIrfkQ+xX3MS4nnqdGjAIC0MKiaa/+Glwu4LoLlJ3/Ks75RNLYHye+7IXNDv2FnjZu4zhKH6LtzS9eww1PqOXutlbLWvRdCHe9Di75RcSXNMBWSZMwt+; Path=/, Set-Cookie: JSESSIONID=00000nRkryRT3eBiIHQliOISDo-:19aro79o6; Path=/; HttpOnly, Set-Cookie: currentUserName=Test User; Path=/, Set-Cookie: currentUserHandle=8E825631-A6E4-4D1C-9360-76E7F588EC2F; Path=/, Set-Cookie: currentUserHasLinks=false; Path=/, Vary: Accept-Encoding,User-Agent, Connection: close, Transfer-Encoding: chunked, Content-Type: text/html;charset=UTF-8, Content-Language: de-DE]

I am definitely logged in and the ProfileService is instantiated properly, because creating a community works perfectly.

But could you say me what's wrong with this?

Best regards

Siri

prb112 commented 8 years ago

You should test your XML Payload using a tool like cURL.
You should get the API to post to from the service config - GET https:///dogear/api/app You'd see the URL is https:///dogear/api/app?email=EMAIL@us.ibm.com

You should also know that the Dogear content is not equivalent to Community Bookmarks.http://www-01.ibm.com/support/knowledgecenter/SSYGQH_2.5.0/com.ibm.connections.25.help/r_api_common_bookmark_entry_content3.html

Use this format

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:snx="http://www.ibm.com/xmlns/prod/sn" xmlns:thr="http://purl.org/syndication/thread/1.0">
  <category term="bookmark" scheme="http://www.ibm.com/xmlns/prod/sn/type">
</category>
  <title type="text">IBM Bookmark Test NEW</title>
  <content type="text">IBM Description NEW</content>
  <category term="ibm"/>
  <category term="sbt"/>
  <link href="http://www.ibm.com/"></link>
</entry>
SiriSch commented 8 years ago

Thanks, that helped!