Posting Blog Entries to a Community - ibm-connections

Our tool is submitting blog entries to the idation blog for a configured community by using the Connections API.
Therefore, I use the following workflow, given only a community ID:
1) query /blogs/api/blogs?commUuid=<ID_HERE>&blogType=ideationblog
2) retrieve the link to the communities ideation blog from the xml result of aboves query. the xPath for this is "/app:service/app:workspace/app:collection[a:category[#term='entries']][1]/#href"
3) post the created blog entry payload to this url.
This all worked fine in our environment. However, when I deployed this at a customer, it did not work anymore. The url from the first step returns an empty xml document, and the following steps thus cannot be executed. I tried to query different urls on the customers server like /blogs/{homepageHandle}/api/blogs?commUuid=&blogType=ideationblog which work fine, however the query to the api service document above is the only one which contains the collection element with the link I need.
Is there any other API call I can do, to get this url? Do you know of any reason, why the call is working just fine in our environment, but fails at the customer? Might this be an access rights problem?
I am aware, that I could probably just create a url like "blogs//api/entries" and post to it, however I would prefer the above way, since I only have the communityUuid configured, and also because it is exactly the way that the API Documentation describes:
http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.5+API+Documentation#action=openDocument&res_title=Creating_blog_posts_ic45&content=pdcontent
ServiceDoc -> Collection -> href
UPDATE:
This might be a problem with the SBT really. My assumption, that an empty xml document was returned was wrong, it is rather that calls via the SBT Endpoint classes are returning null.
Endpoint endpoint = EndpointFactory.getEndpoint("connections");
Object result = endpoint.xhrGet("/blogs/api"); // also tried for /blogs/<homepage>/api
When I again tried those URLs in the Browser, I got the complete results. Problem with all this is, that I can neither reproduce this in our own environment nor am I able to debug this at the customer. I tried to catch possible exceptions from this, but none are thrown. It's just that the result is null.
To clarify: The same requests work perfectly fine in our own (Connections 4.0) environment, and also from the browser at the customer. I am of course using the same user to authenticate as well in the browser as in the API calls.
endpoint.isAuthenticationValid();
also returns true, so seemingly no problem there...

I have long ago given up trying to follow the IBM documented REST API instructions (not least of all because it always ends in a myriard of REST requests just to get to the URL I need to send my request to).
I tried both your URLs (/blogs/api/blogs?commUuid=... and /blogs/<homepage>/api/blogs...) against all our Connections 4.5 systems, but although I do get an xml document back it doesn't contain a reference to the ideationblog anywhere (and yes, I made sure to quest against a Community that does contain an ideation blog).
This is a dirty workaround, which you mentioned you did not want to do, but which I do use because the documented way doesn't work:
To post blog entries, you need to POST against
/blogs/<bloghandle>/api/entries
To find out the handle (<snx:handle>) of the ideation blog in your community, you can do the following:
1.) Get the widgets-feed for the community: /communities/service/atom/community/widgets?communityUuid=...
2.) Navigate to the entry of the Ideation Blog widget: <snx:widgetDefId>IdeationBlog</snx:widgetDefId>.
Unless someone in your customer system has messed with the widgets-config.xml, the widgetDefId will be IdeationBlog.
3.) Take the <snx:widgetInstanceId> text of the Ideation Blog entry.
That is the handle of your ideation blog. (Yes, community ideation blogs are created with the widgetInstanceId of the Ideation Blog widget as handle. Normal blogs are created with some mashup of their title as handle). You can now construct the URL to post the entries to.

Related

Save column of numbers from url to python array

I want to save the data column from this url to an array in python. I tried it with, for instance, pandas.save_table:
import pandas as pd
pd.read_table('https://adventofcode.com/2019/day/1/input', sep='')
but I get HTTPError: HTTP Error 400: Bad Request and I think this is not the right way to do that.
Can someone help me with that?
If you try to open the link in your question (in a browser using incognito mode or something similar i.e. delete your cookies) you'll see that you need login into the website to access the page. This is why the you're getting a 400 Bad Request error as a response from the server.
From the FAQ section of the website that you're trying to access:
How does authentication work? Advent of Code uses OAuth to confirm
your identity through other services. When you log in, you only ever
give your credentials to that service - never to Advent of Code. Then,
the service you use tells the Advent of Code servers that you're
really you. In general, this reveals no information about you beyond
what is already public; here are examples from Reddit and GitHub.
Advent of Code will remember your unique ID, names, URL, and image
from the service you use to authenticate.
The website uses OAuth to handle logins to the url that you create will need these access tokens. You can use a library like python-oauth2 to help you with this (there are others so you can read around and decide which you'd like to use). Creating and understanding how to make http requests is beyond the scope of this answer. I'd suggest you have a look around on the internet for some explanations and try again, if you have get stuck please ask another question. Otherwise it'll probably be easier to save the file from your browser...But I'll leave this answer here for the next person who runs into the same problem.

Kentico: PortalTemplate.aspx explicitly throwing a 404 error when directly invoked

We work on a product that is a series of components that could be installed on different CMSs and provide different services. We take a CMS agnostic approach and try to use the same code in all the CMSs as much as possible (we try to avoid using CMS API as much as we can).
Some part of the code needs to work with the current URL for some redirections so we use Request.Url.ToString() that is something that has worked fine in other environments but in Kentico instead of returning the current page we always get a reference to CMSPages/PortalTemplate.aspx with a querystring parameter aliasPath that holds the real URL. In addition to that, requesting the Template page using a browser gives you a 404 error.
Example:
Real URL (this works fine on a browser):
(1) https://www.customer.com/Membership/Questionnaire?Id=7207f9f9-7354-df11-88d9-005056837252
Request.Url.ToString() (this gives you a 404 error on a browser):
(2) https://www.customer.com/CMSPages/PortalTemplate.aspx?Id=7207f9f9-7354-df11-88d9-005056837252&aliaspath=/Membership/Questionnaire
I've noticed that the 404 error is thrown explicitly by the template code when invoked directly. Please see below code from Page_Init method of PortalTemplate.aspx.cs:
var resolvedTemplatePage = URLHelper.ResolveUrl(URLHelper.PortalTemplatePage);
if (RequestContext.RawURL.StartsWithCSafe(resolvedTemplatePage, true))
{
// Deny direct access to this page
RequestHelper.Respond404();
}
base.OnInit(e);
So, if I comment the above code out my redirection works fine ((2) resolves to (1)). I know it is not an elegant solution but since I cannot / don't want to use Kentico API is the only workaround I could find.
Note that I know that using Kentico API will solve the issue since I'm sure I will find an API method that will return the actual page. I'm trying to avoid that as much as possible.
Questions: Am I breaking something? Is there a better way of achieving what I trying to accomplish? Can you think on any good reason I shouldn't do what I'm doing (security, usability, etc)?
This is kind of a very broad question so I was not able to find any useful information on Kentico docs.
I'm testing all this on Kentico v8.2.50 which is the version one of my customers currently have.
Thanks in advance.
It's not really recommended to edit the source files of Kentico, as you may start to run into issues with future upgrades and also start to see some unexpected behaviour.
If you want to get the original URL sent to the server before Kentico's routing has done its work, you can use Page.Request.RawUrl. Using your above example, RawUrl would return a value of /Membership/Questionnaire?Id=7207f9f9-7354-df11-88d9-005056837252, whereas Url will return a Uri with a value of https://www.customer.com/CMSPages/PortalTemplate.aspx?Id=7207f9f9-7354-df11-88d9-005056837252&aliaspath=/Membership/Questionnaire (as you stated).
This should avoid needing to use the Kentico API and also avoid having to change a file that pretty much every request goes through when using the portal engine.
If you need to get the full URL to redirect to, you can use something like this:
var redirectUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Request.RawUrl;

Retrieve BLOGS_UPLOADED_IMAGES in java

I have some java code that retrieves blogs through the REST API's. I am not using the social business toolkit, but we have our own framework for that.
The application works perfectly on an on-premise connections environment and has worked on multiple versions.
However when switching to Connections Cloud, some parts stopped worked.
We get a 403 - Forbidden exception on 2 occasions:
Getting the details of a blog post: /blogs/[blog-id]/feed/entry/atom?entryid=[entry-id]
Getting images inside the blog post: /blogs/[blog-id]/resource/BLOGS_UPLOADED_IMAGES/[image file name]
I have fixed issue 1) by switching to the plublishing API: /blogs/[blog-id]/api/entries/[entry-id].
I cannot find a way to fix issue 2). I have also found 2 other image urls:
https://apps.ce.collabserv.com/blogs/[blog-id]/api/media/[file-name]
https://apps.ce.collabserv.com/blogs/[blog-id]/api/media/BLOGS_UPLOADED_IMAGES/[file-name].media
Both return:
<sp_0:error xmlns="http://incubator.apache.org/abdera" xmlns:sp_0="http://incubator.apache.org/abdera">
<code>404</code>
<message>Not Found</message>
</sp_0:error>
I want to authenticate by using Basic Authentication when possible. This does not appear to work with the given 403 urls.
My guess is that this the basic authentication header is not picked up. I have seen this before.
I used to fix this by first calling another URL that does support basic authentication and using the Ltpa cookies to authenticate the image url.
This also does not work: I do get LtpaTokens, but when I pass all the cookies to the URL, the image still does not work.
I prefer not to use OAuth of OAuth 2 at this moment. Is there any other way to fix this?
Anybody else managed to retrieve BLOGS_UPLOADED_IMAGES?
The issue is can also be reproduced in a browser.
Make sure you are not yet authenticated and the blog has posts with
images
Go to /blogs/[blog-id]/api/media
Authenticate using the popup in the browser The Atom feed now appears. This contains the images of your blog.
403 when opening:
/blogs/[blog-id]/resource/BLOGS_UPLOADED_IMAGES/[image]
404 xml when opening: /blogs/[blog-id]/api/media/* links

Getting all GitHub users through github-api

The GitHub API documentation says that the url
https://api.github.com/users
will give all users in the order they signed up, but I only seem to get the first 135.
Any ideas how to get the real full list?
Please use since parameter in your GET request.
https://api.github.com/users?since=XXX
Probably it's done this way to limit the resources needed to handle such request. Without such limit it's just asking for DoS attack.
If you check the response headers for that request Github provides pagination links under the header Links
Link: <https://api.github.com/users?since=135>; rel="next", <https://api.github.com/users{?since}>; rel="first"
I believe since their api v3 Github has been moving towards a hypermedia api.
Github Hypermedia API
EDIT
This is beyond the scope of this question but its related. To learn more about hypermedia API and REST. Take a look at these slides by Steve Klabnik
http://steveklabnik.github.com/hypermedia-presentation/#1
Both of the existing answers are 100% correct, but I would advise you to use a wrapper for whatever language you happen to be doing this in. There are plenty of them and there is an official one for ruby (Octokit). Here is a list of all of them.
You can filter on type:user like this:
https://api.github.com/search/users?q=type:user
See Also: GitHub API get total number of users/organizations

How do I override xhr-src?

I created a userscript for myself which is active on all webpages i visit. It sends data to my debugger/app via jquery's post ($.post).
I notice one site not allowing me to send data even though it worked before and after a quick look it appears there is some kind of error via xhr-src. It appears the response headers has a 'X-Content-Security-Policy' which list a bunch of sites (google being one). So when i try to do a post to localhost:myport/ it violates the rule thus doesn't post.
What can I do to get this working again? I can't exactly edit the headers (unless i write my own http proxy?) would i be able to create an iframe using localhost:1234/workaround and post via that? But the issue is i still dont know if thats a violation or how to give it data.

Resources