Giter VIP home page Giter VIP logo

sprest's Introduction

NuGet Current Version Downloads Total Downloads Gitter chat Donate

The SharePoint REST Framework was designed for SharePoint 2013, but works in both SharePoint 2013/Online (Classic/Modern) pages. This framework is designed to remove the overhead required for SharePoint development, allowing the developer to focus on the client requirements.

intellisense

References

  • gd-sprest - An easy way to execute requests against the SharePoint 2013/Online REST API
  • gd-sprest-def - Generates TypeScript definition files from the $metadata SharePoint REST endpoint, for this library.
  • gd-sprest-bs - Extends the Bootstrap Framework with components designed for SharePoint 2013/Online.

Core Library

The gd-sprest library is similar to the pnp-js, with the main difference being the ability to be used within the browser console window. This feature provides a "Powershell-Like" experience within the browser console window. This feature was designed for developers working in restricted SharePoint environments, or do not have access to the server or powershell access. Some additional benefits of the library are listed below:

  • Designed to work in restricted SharePoint environments with limited access to the SharePoint Farm, Web App, Site Collection, Root Web, etc
  • Helper functions designed to help create solutions in restricted SharePoint environments
  • Ability to create reusable scripts/solutions
  • Intellisense is available for JavaScript/TypeScript
  • Ability to execute live requests from the browser console, helps to debug issues in production
  • Ability to use pure JavaScript if NodeJS is not available to be installed for TypeScript/WebPack/Babel

Bugs/Issues/Missing Functionality

Click Here to report any bugs, or requests any missing endpoints or function. You can also use create issues for requesting a code example. Pull requests are welcomed for anyone interested in submitting them.

Intellisense

The SharePoint REST API has a $metadata endpoint which contains the intellisense for its objects. This library's intellisense is generated from this data to ensure the latest functions/methods are made available for OnPremise and Online.

The intellisense for this library is included as part of the npm installation. It supports both JavaScript and TypeScript. The nuget installation includes the bundled definition file as part of the library.

Modern Experience in SharePoint 2013

One of the key reasons of creating this library, was to give an easy way to develop using the modern web stack in SharePoint 2013 environments.

SPFx Support

Follow the documentation for steps on configuring this library with SPFx projects.

Security

The REST api execute requests based on the user's permissions. There is no way to elevate privileges requests against the SharePoint REST.

sprest's People

Contributors

gunjandatta avatar mikevasiloff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sprest's Issues

Sample using Search

Hi,
Any sample how to use Search would be appreciated. It isn't quite obvious how to make a simple search query.

Thank you!

Accessing Results Property/Method Issue

There is a setTimeout that adds the methods to properties. It waits 10 ms which should be set to 0, to immediately start updating the properties. This can cause an error when a method is expected, but not available.

Unable to Create List Items Setting Multi-User Value

On creation of a list item, it's not accepting multi-user field values to be set. This is due to the metadata type not being set correctly. You can set it to SP.ListItem and it will work for none complex fields, but not Multi-User fields for instance.

Creation/updating view is using the title of the view rather than the staticName

When updating a view, the view is selected based on the title and not on the staticName. This causes an issue when the site is installed with another language as English, when we would like to update the default view 'AllItems'. The view name is translated by SP, so using 'All Items' creates a new view called 'All Items' instead of updating the current view with the staticName 'AllItems' but the Name depending on the language of the site collection.
A workaround is to create a configuration file for each language instead and selecting the one based on the language before executing the .install().

REST API & filter URL issue in AddIn mode

Within an AddIn application ($REST.DefaultRequestToHostFl = true), I am running into a URL error, in the case that the this.targetInfo.endpoint includes already a '?'. I found this error when using the save functionality of the itemForm component from the gd-sprest-react library.
The solution would be to replace the following code:
this.requestUrl = lib_1.ContextInfo.webAbsoluteUrl + "/_api/SP.AppContextSite(@target)/" + url[1] + (this.targetInfo.endpoint ? "/" + this.targetInfo.endpoint : "") + "?@target='" + url[0] + "'";
with this one:
this.requestUrl = lib_1.ContextInfo.webAbsoluteUrl + "/_api/SP.AppContextSite(@target)/" + url[1] + (this.targetInfo.endpoint ? "/" + this.targetInfo.endpoint : "") + ((this.targetInfo.endpoint.indexOf("?")==-1) ? "?" : "&" ) + "@target='" + url[0] + "'";
This checks if there is already a ? in the endpoint, and introduce a '&' instead of the '?'.
I tested this solution with the indicated component and seems to work OK.

Context Information is Null

The content information class is return "null" information, causing the api to target the absolute root, instead of the current site collection.

Void is not assignable to parameter of type boolean

Hi, (me again)
I tried to add Data.tsx from your sample project : sprest-fabric-react/SPREST.FabricReact/SPREST.FabricReact.UX/src/components/List/data.tsx

image

unfortunately i get the following error. error TS2345: Argument of type '(items: IListItems) => void' is not assignable to parameter of type 'boolean'.

I can change "(items:Types.IListItems)" to "(items:any)", then it compiles. What do you recommend?

` // Execute the request
.execute((items:Types.IListItems) => {
let data: IData[] = [];

                    // Parse the items
                    for (let item of items.results) {
                        // Add the item to the data array
                        data.push({
                            Title: item["Title"],
                            County: item["County"],
                            State: item["State"]
                        });
                    }`

Typescript semantic errors

Hi (great looking tool)
Quick question; i am trying to test this out. however, whenever i use gulp to build i get 430 typescript semantic errors. anyway to ignore these errors? or should i have use some sort of setting somewhere?

example error
C:/.../gd-sprest/build/definitions/list/list.d.ts(21,56): error TS7006: Parameter 'IList' implicitly has an 'any' type.
[12:10:43] TypeScript: 430 semantic errors

Email Not Working

Emails are not sending and throws an error when executing the "execute" method.

Question: Web getsubwebsfilteredforcurrentuser with select & chaining

Hi,
I can query subwebs Titles in SharePoint Online using query such as /_api/web/getsubwebsfilteredforcurrentuser(nwebtemplatefilter=-1,nconfigurationfilter=-1)?$select=Title.

How would I combine the Select when using SPREST? It is not allowed after so query such as web.getSubwebsFilteredForCurrentUser(-1, -1).query({Select: ["Title", "Url"]}).execute() doesn't work.

Also, cannot chain anything, as getting error "$REST.Web(...).getSubwebsFilteredForCurrentUser(...).execute(...).Lists is not a function", e.g., when trying this:

$REST.Web().getSubwebsFilteredForCurrentUser(-1, -1).execute()
    .Lists("pages").Items().query({Select: ["Title", "ServerRelativeUrl"]}).execute();

but also all samples in Wiki, such as this give similar error

// Get the current web
$REST.Web()
    // Get the Field Collection
    .Fields()
    // Query for all fields with the name of 'Title'
    .query({
        Filter: "Title eq 'Title'"
    })
    // Execute this request
    .execute()
    // Get the 'Dev' List
    .Lists("Dev")
    // Get the items
    .Items()
    // Execute this request after the previous one completes
    .execute(true)
    // Get root folders
    .Folders()
    // Execute this request after the previous one completes
    .execute(true)
    // Wait for the requests to complete
    .done(function(fields, items, folders) {
        // This code will execute after all requests have completed
    });

Am I missing something essential especially in the second chaining issue?

Custom URL Parameters for Items query

It would be great if the ODataQuery Object allowed a custom url parameter, that allows you to add any kind of string to the url. In my case I want to manually add $skiptoken=Paged=TRUE&p_ID=X to the URL generated.

Collection Returning 1 Result - Error on Add

The url of the collection is incorrect (User Custom Actions for instance), since we are defaulting single collection results to act as that object. This will need to be removed to ensure sub-methods of the collection work.

Query > than 5000 items

Hi,

How can I get more than 5000 items ?

I'm currently using list.Items().query({ Top: 5000, GetAllItems: true }).execute()

Thanks in advance, great lib!

AttachmentFiles Property Overwritten

Using the query function and expanding the AttachmentFiles for a list item, the "AttachmentFiles" property is being overwritten by the library.

Email API not found

Hi,

In a previous release of sprest i was using $REST.Email but I can't find it in this release. Is it going to be replaced by something else ?

Thanks!

URL used for PeoplePicker in ItemForm for AddIn (DefaultRequestToHostFI =true)

When using the ItemForm from an application (AddIn), for a list from the WebHost (DefaultRequestToHostFI =true), the query called to retrieve the users (SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser) returns the following error:

Cannot find resource for the request SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser

I think that the SP.AppContextSite(@target) part of the url should be removed. for this query:

Current call

/_api/SP.AppContextSite(@target)/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser?@target=%27https://xxxxx.sharepoint.com/sites/APPS%27

Call which should be working

/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.ClientPeoplePickerSearchUser

It is not possible to set the flag DefaultRequestToHostFI to 'false', since the other calls should not be impacted/we do not have the possibility to do this without impacting the ItemForm

Unable to Get List in Host Web

Using the new $REST.List('name') works when executing from a web to the current, but this will not work from an app web accessing the list in the host web.

List querying with top doesn't return all rows

I've been trying out the List library, and came across a problem when using GetAllItems: true and Top: x. It returns only the amount of rows that I specify in Top.

  var queryObj = {
    Select: _columns,
    Expand: _expand,
    Top: 2,
    GetAllItems: true
  }
    List.getByEntityName(listName, list => {
      list.Items().query(queryObj).execute(items => {
        console.log(items)
     })
   }, site)

items logs only 2 items in this example, although there are a few more in the list. As per the docs I thought that the execute callback would only be called if all items have been queried and there is no next property anymore.

List renamed after re-installation when using the TitleFieldDisplayName

I am using the Configuration.install() functionality to create the lists on the SharePoint Hostweb.
When using the TitleFieldDisplayName, in order to rename the Title column of a list and re-installing lists, the existing list is renamed, using the DisplayName for the Title column.
When removing TitleFieldDisplayName from the configuration, the list keeps his name and the list is updated as expected.

Parallel GetAllItems query

Right now, GetAllItems and Top is used to query all items from a list/library serially. Meaning, the next batch of items is only retrieved, once you get the answer from the one bevor, that has the next URL.

With IListItem.ItemCount you know beforehand how many items there are in a list. What I've been doing before using this library is to build the requests for the batches manually. You know how many items there are, and how large a batch is (via the Top property).

Async Lists Fails in App Web

The following is not working when executing w/in an app web to the host web.

Example:
new Lists_Async({ url: "[host url]", callback: function(lists) {
...
}});

The lists object is not correct.

bug in query string builder for OData

(new $REST.List("SomeList")).Items().query({Filter:"Title eq 'Some Text'"}).execute()

Will build the query string and call

https://PathToWeb/_api/lists/getByTitle('SomeList')/Items/?$filter=&Title%20eq%20%27Some%20Text%27

Object.defineProperty(OData.prototype, "QueryString", {
                // Query String
                get: function () {
                    var qs = "";
debugger;
                    var values = [];
                    // Get the query string values for the properties
                    values.push(this.getQSValue("$select", this._select));
                    values.push(this.getQSValue("$orderby", this._orderBy));
                    this._top ? values.push("$top=" + this._top) : null;
                    this._skip ? values.push("$skip=" + this._skip) : null;
                    this._filter ? values.push("$filter=", this._filter) : null;
                    values.push(this.getQSValue("$expand", this._expand));
                    // Parse the values
                    for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
                        var value = values_1[_i];
                        // Ensure a value exists
                        if (value && value != "") {
                            // Append the query string value
                            qs += (qs == "" ? "" :"&") + value;
                        }
                    }
                    // Return the query string
                    return qs;
                },
                enumerable: true,
                configurable: true
            });

The problem is that the qs append-er will take qs="$filter=" meaning qs=="" is false and then logically append & before the filter text.

Views on a list not created/update when there is no space in the Title of the list.

I am using the Configuration.install() to create the lists, with their views on the Hostweb of my application. I give the list a title without any space (' ') in the title, like <<Title: "TestProject">> the views are not created for this list. When adding a space into the title, like <<Title: "Test Project">> the views are created correctly.
It seems that the space is necessary to be able to create the views.

Query List with internal name

/_api/web/lists exposes the d:EntityTypeName property for all lists. By querying /_api/web/_lists first, you could select the d:Title of the list that matches the EntityTypeName and then make the call to /_api/web/lists/getbytitle('...').

The downside is to have 2 calls per list site query, but then you don't have any troubles adapting your code if you change the display name.

List Items CAML Query Not Working

Using typescript to generate a CAML query using the [CAML Query] with new lines to help w/ complex queries. The \n character is causing the query to not execute.

addView Properties Not Correct

Creating a view, the property should be ViewQuery not Query. ViewFields is of type "Collection" which I'm not sure how to do via the REST api.

Query List on different site collections

I'm not sure if this is already implemented, but is there a way to pass the site collection as well? Right now, I think, it's only possible to query lists on the same site collection the user is on. There are usecases though, where you would want to query multiple lists from different site collections.

Basically this would be done like this: List.getByEntityName(siteCollection, listName).

The request would be: https://<server>/<siteCollection>/_api/web/lists/....

Methods not added to results with 1 result

The "methods" are not being added to collections with 1 result. Example:

Query a list with expanding the views collection, assuming only 1 view exists. The "methods" for the view collection object are missing.

Search query functionality in SharePoint Hosted AddIn creates wrong url

When using the search functionality within a SharePoint Hosted AddIn, the url of the REST call is not correct. It seems that the way the search is handled in this case is an MS exception. I found the following article describing the same issue and the solution here

In order to fix this issue, I added a check in the creation of the url: (file : targetInfo.js)
//Check if this is part of the search if (this.targetInfo.endpoint.startsWith("search")) { // Set the request url this.requestUrl = template .replace(/{{Url}}/g, lib_1.ContextInfo.webAbsoluteUrl) .replace(/{{EndPoint}}/g, endpoint) .replace(/{{TargetUrl}}/g, ""); } else { // Set the request url this.requestUrl = template .replace(/{{Url}}/g, lib_1.ContextInfo.webAbsoluteUrl) .replace(/{{EndPoint}}/g, "SP.AppContextSite(@target)/" + endpoint) .replace(/{{TargetUrl}}/g, "@target='" + this.targetInfo.url + "'");
This allows the query to be executed, but made me run into a second issue, the way the query was executed was considered 'not save'. Therefore I changed the way to supply the parameters to the query : (file : methodInfo.js)
'// Set the url if (this.methodInfo.name === "query") { url += params.length > 0 ? "?" + params.replace(/, $/, "") + "" : ""; } else { url += params.length > 0 ? "(" + params.replace(/, $/, "") + ")" : ""; }
This allows me to run the search query from a SharePoint hosted Add-In.
I did not ran any additional tests yet, to see if I caused any impact on your way of executing the queries...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.