Welcome to my blog, stay tunned :
Home

REST

REST is heavily used in SOA architectures. All the posts tagged with REST refer to using REST inside of SharePoint 2010 and 2007.

Search Engine not working fine in your App?

Hi,

I know that might sound stupid and it really is but I spent recently a few hours trying to figure out why the Search Engine wasn't working fine when queried from my App.
It turned-out that I forgot to ask the permission to use it. So, I was missing this line in my AppManifest.xml:





While this is very stupid, this little distraction made me realize that the system isn't behaving as expected. Indeed, one could expect that the App Model throws an exception such as "Attempt to perform an unauthorized operation" but it doesn't. It's actually even querying the Search Engine successfully but simply, no results are returned.
It is behaving as if it was applying some kind of security trimming but it's not because the App had full control over the site collection...Morality, just don't forget this line and you should avoid some headaches :).

Happy Coding!



Demo SharePoint-Hosted App showing how to use the REST API (CRUD, micro-blogging, following content, people, search)

Hi,

Update : I've published this App to the online SharePoint Store which facilitate its installation. The App is available here http://office.microsoft.com/en-us/store/rest-api-demo-WA104068939.aspx?q.... However, since the SharePoint Store doesn't permit Tenant Full Control permissions, the App capabilities are a little bit reduced compared to the one published on CodePlex

Creating a micro blog with new hashtags with the REST API

Hi,

Update 04/2013 download my demo App at http://sptoolbasket2013.codeplex.com/

Similarly to my previous post, here is how to create a new hashtag inside of a microblog using the REST API from a SharePoint-Hosted App. Basically, you also have to address the ContentItems

Creating a micro blog with mentions with the REST API

Hi,

Update 04/2013 download my demo App at http://sptoolbasket2013.codeplex.com/

As I've struggled a lot to get this working and since I coudln't find the information anywhere, I've decided to create this blog post that shows how you can create a microblog entry in SharePoint 2013 for the connected user (from a SharePoint-Hosted App) using mentions.

On MSDN, you can find a sample showing how to create a microblog here : http://msdn.microsoft.com/en-us/library/jj822974.aspx. While this is already a good start, there is no mention about posting more complex microblogs and for instance, embedding mentions to other people. If you try just to add @user in the text body, you won't end up with a valid solution :).

So, after a bit of digging, I eventually found out how this works. In the below example, I'm targetting users demo and eni by saying hello to both of them. This is the result when posted:

and here is the JSON data you have to send via a POST query to /_api/social.feed/my/Feed/Post to do that:

{
    'restCreationData': {
        '__metadata': {
            'type': 'SP.Social.SocialRestPostCreationData'
        },
        'ID': null,
        'creationData': {

            '__metadata': {
                'type': 'SP.Social.SocialPostCreationData'
            },
            'Attachment': null,
            'ContentItems': {
                'results': [
                    {
                        '__metadata': {
                            'type': 'SP.Social.SocialDataItem'
                        },
                        'AccountName': 'dc07\\demo',
                        'ItemType': 0,                                        
                        'Uri': null
                    },
                    {
                        '__metadata': {
                            'type': 'SP.Social.SocialDataItem'
                        },
                        'AccountName': 'dc07\\eni',
                        'ItemType': 0,
                        'Uri': null
                    }
                ]
            },
            'ContentText': 'Hello @{0} and hello @{1}',
            'UpdateStatusText': false
        }
    }
}

The magic happens with the ContentItems collection where you have to provide the information about each targetted account which you reference after in the ContentText property by their respective index.

Happy Coding!

Double quotes & single quotes when using the Search REST API of SharePoint 2013 combined with KQL from JavaScript

Hi,

Update 04/2013 download my demo App at http://sptoolbasket2013.codeplex.com/
I've been facing a quite strange issue when using the new search REST API of SharePoint 2013 and you might be facing the same kind of issue so as it took me a while to figure out the problem, I thought it was a good idea to share both the problem and the fix.
Double quotes
First, the problem! When trying to pass double-quotes into the querytext parameter. If you do not use the KQL syntax, you don't have any problem. So, if I transmit this:






/_api/search/query?querytext='test%22'


it's working fine.
If you're using the KQL to say for instance that you want to retrieve only items whose title equals "test". You can do it this way:

/_api/search/query?querytext='Title="test"'


Usually, you'll make sure to encode the full querytext parameter. However, with the KQL syntax, you can use parenthesis and if you repeat the same query than before with parenthesis:


/_api/search/query?querytext='(Title="test")' 
=> encoded value is :/_api/search/query?querytext='%28Title%3D%22item%201%22%29'


it will also work fine. Usually you'll use parenthesis if you want to apply priorities among multiple search criteria, however this is not a must since the above query works also fine but...strangely enough, if you add a double quote in the value, despites of the fact that this is encoded:


/_api/search/query?querytext='(Title="test " double quote")' 
=> encoded value is :::/_api/search/query?querytext='%28Title%3D%22test%20%22%20double%20quote%22%29'


You see that the value test " was encoded to test%20%22 so the double quote is escaped, at least from a web point of view, you will still receive the following error from the service:


Status:500Error:{"error":{"code":"-1, Microsoft.Office.Server.Search.REST.SearchServiceException","message":{"lang":"en-US","value":"We didn't understand your search terms. Make sure they're using proper syntax."}}}


and the reason of that are the parenthesis...If you get rid of them, you won't have that message anymore. So, make sure to use the parenthesis only if you need them...even with multiple search criteria. So, I don't know exactly why the parenthesis have this effect but for sure, they seem to have a weird impact.
Actually, the double quote character is meaningfull for the KQL engine so I think that encoding doesn't change anything and the character is still interpretated somehow by the KQL engine. I tried many different ways of escaping it with %22, \", \x22 in Javascript...and none of them is working.
If I have an item that has this value with " quotes and I try to search using the encoded form, I'll have no error without parenthesis but it won't return any result no matter how I'm encoding the ", I'll have the error described earlier with the parenthesis and it will just work fine with the right results if I replace " by nothing.
Single Quote
Here it's even worste, whatever you're trying to do, the server will crash with an error whether you're working with KQL or even with a basic search term...and the reason of this is because the ' character is enclosing the value of the querytext parameter and that's most probably why it goes mad. So, again, if I just remove the ' character from the search value, it's finding results correctly even when you make an exact match. So if you search for Title="test single quote", items whose the title is test ' single quote are returned...
So, not sure that removing both ' and " from the search terms is the right workaround but it seems to work and you'll probably avoid some headaches.
Note that these problems are only encountered when working with GET and _api/search/query, you won't run into them when using _api/search/postquery because there, you can just use JSON.stringify of the entire request and pass it as the data parameter and that will work like a charm.

Happy Coding!








SharePoint 2013 Preview REST Offering Extension

Hi,

Update 04/2013 : visit this link http://www.silver-it.com/node/130 to download a demo SharePoint-Hosted App that's demoing most of the REST API capabilities
SharePoint 2013 has extended its REST offering in order to provide the external world an easy and standard way to interact with SharePoint objects. In 2010, Microsoft had already made an important step (compared to 2007) by providing both the Client Object Model (CSOM) and a few REST/oData enabled services such as ListData.svc.