ವರ್ಗ ಆರ್ಕೈವ್ಸ್: ಉಳಿದ

HTTP 406 ದೋಷ ಶೇರ್ಪಾಯಿಂಟ್ ಉಳಿದ ಅಂಶಗಳು ಅಭಿಪ್ರಾಯ ವಿರುದ್ಧ ಕೋನೀಯ $ http.get ಬಳಸುವಾಗ

ನವೀಕರಿಸಿ: Marc AD ndersson pointed out this great piece of info: HTTP://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/. That explains a lot :).

That may be the worst title of a blog post ever! Anyhoo.

I typically do all of my prototyping against an O365 instance. I have my personal instance so that I don’t have to be worried about affecting anyone else. As an aside – remember when we call carried around virtual machines on our laptops with MOSS – SQL Server, IIS, deciding Hyper-V vs. VMWare? Anyhoo…

I had developed an app using Angular in this environment that does, ಇತರ ವಿಷಯಗಳ ನಡುವೆ, ಈ:

$http.get(serverUrl)
.success(ಕ್ರಿಯೆ(ದಶಮಾಂಶ, ಅಂತಸ್ತು, headers, ಸಂರಚನಾ) {

var getLinksResponse = data;

getLinksResponse.value.forEach(ಕ್ರಿಯೆ(theResult) {

// and so on and so froth

This was working just fine in two different SharePoint online environments. ಹೇಗಾದರೂ, when my colleague ported it to a Cloudshare instance, he was getting an HTTP 406 ದೋಷ (which was the first time I ever got that one, so … yay, I guess). We did a bit of research and noticed that the “Accept” header was off. SharePoint online was perfectly happy with:

Accept: application/json

But the cloudshare instance (which is SP on prem, hosted in a virtual server) wanted the classic “odata=verbose” added in as well:

Accept: application/json;odata=verbose

To fix that, we added the header as such:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,ಸಂರಚನಾ)
.success(ಕ್ರಿಯೆ(ದಶಮಾಂಶ, ಅಂತಸ್ತು, headers, ಸಂರಚನಾ) {

var getLinksResponse = data;

getLinksResponse.value.forEach(ಕ್ರಿಯೆ(theResult) {

// and so on and so froth

That got rid of the 406, but it also changed the format of the response. It was more … verbose. (haha!) More changes were required and here’s the final result:

var config = {headers: {
‘Accept’: ‘application/json;odata=verbose’
}
};

$http.get(serverUrl,ಸಂರಚನಾ)
.success(ಕ್ರಿಯೆ(ದಶಮಾಂಶ, ಅಂತಸ್ತು, headers, ಸಂರಚನಾ) {

var getLinksResponse = data;

getLinksResponse.d.results.forEach(ಕ್ರಿಯೆ(theResult) {

// and so on and so froth

This only turned into a 30 minute problem for us, so we lucked out. Hopefully someone finds this useful.

</ಕೊನೆಯಲ್ಲಿ>

ಒಂದು ಶೋಧನಾ ವ್ಯಾಪ್ತಿ ಎಂದು ಸೂಚಿಸಲು ಹೇಗೆ / ವಿಷಯ ಮೂಲವನ್ನು ಬಳಸಿಕೊಂಡು ಶೇರ್ಪಾಯಿಂಟ್ 2013 REST API

I had reason to work with the SharePoint 2013 Search API via REST for the first time. I wanted to search for people, not documents. The key learning here is that you specify content sources via its GUID (or at least in this case). The following jQuery snippet shows how:

    loadExpertsAsync: ಕ್ರಿಯೆ() {

        jQuery.support.cors = ನಿಜವಾದ;

        $.ajax({
            URL: .CreateFullApiUrl() +
                "?querytext='portals'&sourceid='b09a7990-05ea-4af9-81ef-edfab16c4e31'" +
                "&selectproperties='LinkedInProfileUrl,GoogleCirclesProfileUrl,BALargeProfilePictureUrls,BAGridPictures,WorkEmail,Skills,AboutMe,Interests,JobTitle,PastProjects,PictureURL,PreferredName,TwitterHandle,LinkedInProfileUrl,PreferredName,GoogleCirclesProfileUrl'" +
                "&rowlimit=99",
            ವಿಧಾನ: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            cache: ತಪ್ಪಾದ,
            success: ಕ್ರಿಯೆ (ಕಾರಣವಾಗುತ್ತದೆ) {

ಪ್ರಕರಣದಲ್ಲಿ, I’m running the API against SharePoint online. To get the GUID, I followed these steps:

  1. Access the SharePoint admin center
  2. Select “search” from the left hand navigation
  3. Select “Manage Result Sources”
  4. Select “Local People Results”
  5. Look at the URL.

My URL looked something like:

https://xyzzy-admin.sharepoint.com/_layouts/15/searchadmin/EditResultSource.aspx?level=tenant&sourceid=b09a7990%2D05ea%2D4af9%2D81ef%2Dedfab16c4e31&view=1

The sourceid parameter is what worked for me.

(I understand that the sourceid may actually be a sort of permanent thing with SP, but I’ll always check anyway 🙂 ).

</ಕೊನೆಯಲ್ಲಿ>

undefinedನನ್ನ ಬ್ಲಾಗ್ ಚಂದಾದಾರರಾಗಿ.

ನಲ್ಲಿ ಟ್ವಿಟ್ಟರ್ ನನ್ನನ್ನು ಅನುಸರಿಸಿ http://www.twitter.com/pagalvin

ಉದಾಹರಣೆ ಶೇರ್ಪಾಯಿಂಟ್ ಉಳಿದ ಕರೆಗಳು

Here’s a set of sample REST calls that work for me and may help you out as well. ರ 02/2014, there are two examples 🙂

  1. Reference a Column With Spaces In Its Name
  2. Reference a Multi-Select Column
  3. Perform a People Search via REST

 

I’ll add to this as time passes.

Here are some useful inks I’ve found as well:

Reference a Column With Spaces In Its Name

I create a custom list with a column named “Blog Author” (space between Blog and Author).

The $select to reference that column is:

image

Simply replace the space with “_x0020_”. We see the _x0020_ in many examples across the internets and REST is no different.

If you don’t do that, you’re liable to get an error message like this:

The expression “Blog Author” is not valid.

Easy enough.

Reference a Multi-Select Lookup Column

Set up:

  1. Create a custom list named Categories.
  2. Add some categories. I added categories thusly:image
  3. Create another custom list called MockBlog and add Categories as a multi-select list column (or site column if that’s how you roll).

Add some items to your Mockblog list and you’re ready.

An Ajax style call using jQuery will look something like this:

serverUrl  = "/_api/web/lists/GetByTitle('MockBlog')/ಐಟಂಗಳನ್ನು" +
             "?$select=Title,Categories/Title,Blog_x0020_Author/Title" + 
             "&$expand=Blog_x0020_Author,ವರ್ಗಗಳು";

We’re telling SharePoint “Give me the title for all the Categories (Categories/Title). Get the actual values for ಶೀರ್ಷಿಕೆ ಮೂಲಕ $expanding the Categories list.” (My RESTful paraphrasing is probably pretty loose, but this how I’m interpreting it).

If you’re doing this via JavaScript and using Fiddler to look at the output, you get something like this in return:

 

image

(The above is a JSON object)

Perform a People Search via REST

I blogged about this separately. The key is to specify a sourceid parameter whose value is the GUID of the Local People content source. (Content sources used to be called scopes and it’s my-oh-my so hard not to call everything a scope for me!).

ಅದರ ಬಗ್ಗೆ ಹೆಚ್ಚು ಇಲ್ಲಿ ಓದಿ: http://www.mstechblogs.com/paul/?p=10385

 

</ಕೊನೆಯಲ್ಲಿ>

undefinedನನ್ನ ಬ್ಲಾಗ್ ಚಂದಾದಾರರಾಗಿ.

ನಲ್ಲಿ ಟ್ವಿಟ್ಟರ್ ನನ್ನನ್ನು ಅನುಸರಿಸಿ http://www.twitter.com/pagalvin

ತ್ವರಿತ ಮತ್ತು ಸುಲಭ: ಉಳಿದ ಬಳಸಿಕೊಂಡು ಶೇರ್ಪಾಯಿಂಟ್ ಸೈಟ್ ರಚಿಸಿ

There are a lot of resources around that show how to do this, but I couldn’t find a comprehensive go-to link, so here we are.

You can create a SharePoint site using the REST API.  Here’s a fully baked example:

<!--
    SiteRequestForm.html: Collect information and create a site for the user.
-->

<ಕೇಂದ್ರ>
<ಮೇಜು>
    <TR>
        <ಟಿಡಿ>Site Name:</ಟಿಡಿ>
        <ಟಿಡಿ><ಇನ್ಪುಟ್ ಕೌಟುಂಬಿಕತೆ="text" ಹೆಸರು="SiteName" ಐಡಿ="SiteName" /></ಟಿಡಿ>
    </TR>
    <TR>
        <ಟಿಡಿ colspan="2">
            <ಇನ್ಪುಟ್ ಕೌಟುಂಬಿಕತೆ="submit" ಐಡಿ="CreateSiteButton" ಮೌಲ್ಯ="Create the Site" />
        </ಟಿಡಿ>
    </TR>
</ಮೇಜು>
</ಕೇಂದ್ರ>

<ಸ್ಕ್ರಿಪ್ಟ್ SRC="../Plugins/jquery-1.11.0.min.js"></ಸ್ಕ್ರಿಪ್ಟ್>

<ಸ್ಕ್ರಿಪ್ಟ್>
ಎಂದು CreateSiteLogicContainer = {

    createSiteData: {
            "parameters": {
                __metadata: { "type": "SP.WebInfoCreationInformation" },
                Url: "Paultest1",
                ಶೀರ್ಷಿಕೆ: "Paultest1",
                ವಿವರಣೆ: "rest-created web by Paul!",
                ಭಾಷೆ: 1033,
                WebTemplate: "sts",
                UseUniquePermissions: ತಪ್ಪಾದ
            }
    },

    createSite: ಕ್ರಿಯೆ () {

        jQuery.support.cors = ನಿಜವಾದ;

        CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").ವಾಲ್();
        
        $.ajax({
            URL: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add",
            ವಿಧಾನ: "POST",

            headers: {
                "Accept": "application/json; odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").ವಾಲ್()
            },

            ದಶಮಾಂಶ: JSON.stringify(CreateSiteLogicContainer.createSiteData),

            success: ಕ್ರಿಯೆ () { ಎಚ್ಚರಿಕೆ("success"); },
            ದೋಷ: ಕ್ರಿಯೆ () { ಎಚ್ಚರಿಕೆ("error"); }

        });
    },

    wireUpForm: ಕ್ರಿಯೆ () {
        $("#CreateSiteButton").ಕ್ಲಿಕ್ ಮಾಡಿ(ಕ್ರಿಯೆ () {
            ಎಚ್ಚರಿಕೆ("About to try and create the site.");
            CreateSiteLogicContainer.createSite();
        });
    }


}

CreateSiteLogicContainer.wireUpForm();

</ಸ್ಕ್ರಿಪ್ಟ್>

When successful, you get a JSON packet in response like this:

image

My key thoughts and learnings from this include:

  • This approach uses jQuery.  ಪ್ರಕರಣದಲ್ಲಿ, my jQuery library is located in “../plugins.”  You’ll want to change that to point to your favorite JQ location.
  • You can copy and paste that whole snippet into a Content Editor Web Part on a page and it should work just fine.  You’ll want to change the end point of the API call and make sure you reference JQ correctly.
  • The URL is relative to your API’s endpoint.  ಪ್ರಕರಣದಲ್ಲಿ, it’s creating sub-sites underneath https://bigapplesharepoint.com
  • You don’t need to provide a content-length. Some blog posts and MSDN document implies that you do, but happened for me automatically, which I assume is being handled by the $.ajax call itself.
  • This line is required in order to avoid a “forbidden” response: "X-RequestDigest": $("#__REQUESTDIGEST").ವಾಲ್().  There are other ways to do it, but this is pretty nice.  I have lost the link to blog that provided this shortcut.  H/T to you, mysterious blogger!

Good luck and hope this helps someone out.

</ಕೊನೆಯಲ್ಲಿ>

undefinedನನ್ನ ಬ್ಲಾಗ್ ಚಂದಾದಾರರಾಗಿ.

ನಲ್ಲಿ ಟ್ವಿಟ್ಟರ್ ನನ್ನನ್ನು ಅನುಸರಿಸಿ http://www.twitter.com/pagalvin

ತ್ವರಿತ ಮತ್ತು ಸರಳ: ಶೇರ್ಪಾಯಿಂಟ್ ಉಳಿದ ಕಾಲ್ ಮಾತ್ರ ರಿಟರ್ನ್ಸ್ 100 ರೆಕಾರ್ಡ್ಸ್

I’ve been working on a public facing web site for my SharePoint practice here in New York and it uses a lot of JavaScript and REST calls to show content.

During mainline development, I create a small dataset with just 10 or so rows in a custom list and my REST calls all pulled from there.  Once I bumped up the list to have a few hundred rows of data to test for anticipated growth, I found that I was getting exactly 100 rows returned back on my REST calls.

This is a very simple thing to address.  ಪ್ರಕರಣದಲ್ಲಿ (and I believe in most cases), the default REST calls to SharePoint (and possibly as an industry standard?) ಮರಳಿ 100 rows.  To return more than the default, use the $top parameter on your call, ನಲ್ಲಿ:

GET /Insights Dev/_api/web/lists/GetByTitle(‘MockBlog’)/ಐಟಂಗಳನ್ನು?$select=ID,ಶೀರ್ಷಿಕೆ,Categories/Title,Blog_x0020_Author/Title,DatePublished,BlogSummary&$expand=Blog_x0020_Author,ವರ್ಗಗಳು&$filter=&$top=9999

I picked 9999 in this case since I know that growth-wise, there won’t be more than 200 or so rows added to this list in a year.  If it becomes ungainly, we can implement some paging down the road.

</ಕೊನೆಯಲ್ಲಿ>

undefinedನನ್ನ ಬ್ಲಾಗ್ ಚಂದಾದಾರರಾಗಿ.

ನಲ್ಲಿ ಟ್ವಿಟ್ಟರ್ ನನ್ನನ್ನು ಅನುಸರಿಸಿ http://www.twitter.com/pagalvin