57553

SharePoint REST query SP.UserProfiles.PeopleManager special characters

<h3>Question</h3>

This question is an extension of this one I found as a starting point (which works without special characters): SharePoint REST query SP.UserProfiles.PeopleManager

Basically the problem I am having is the query does not accurately respond to accountName with special characters. Specifically, a ' in the last name for this example. The query either returns no results or is a 400 Bad Request.

In the code example I have used encodeURIComponent(), but I have also tried escape() and string escapes "\".

At this point I am assuming its a bug on the MS side, but I cannot find any support documentation, nor any examples of code that have done this successfully.

var siteUrl = _spPageContextInfo.siteAbsoluteUrl; var accountName = "Domain\\LoginFirstName_O'AccountLastName"; $.ajax({ url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { console.log(data); }, error: function (data) { console.log(JSON.stringify(data)); } });
<h3>Answer1:</h3>

Apparently I was closer to the answer than I thought, but I overlooked it. Basically, SharePoint's way of escaping worked in this case. I needed to add code to replace the single ' with ''.

I also found that the request encodes it regardless of the encodeURIComponent(), so for this one I opted to remove it. Up to you if you want to use it or not.

Here is my final code snippet:

var siteUrl = _spPageContextInfo.siteAbsoluteUrl; var accountName = "Domain\\LoginFirstName_O'AccountLastName"; accountName = accountName.replace("'","''"); $.ajax({ url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + accountName + "'", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { console.log(data); }, error: function (data) { console.log(JSON.stringify(data)); } });

来源:https://stackoverflow.com/questions/38793930/sharepoint-rest-query-sp-userprofiles-peoplemanager-special-characters

Recommend

  • no. of arguments in boost::bind
  • how to solve access denied when using UWP GetFolderFromPathAsync
  • robocopy invalid parameter “-”
  • How to open my facebook page in facebook app from button click of an android app [duplicate]
  • Kernel Error in R Jupyter Notebook due to Anaconda?
  • Get all values of a key in a nested array of objects using ramda.js
  • audio controll - backward , forward buttons - Java script
  • Mysql setting default value to be items auto increment key
  • How to add a progress ring to the splash screen in Windows 8?
  • pass sessionid through jquery ajax call to php
  • Identify File Type in Java
  • How to make infinite threaded comments
  • Android NDK refer to external libraries in JNI
  • How to delete first 7 characters of folder name by using batch script?
  • how to get the size of the padding at the end of a class
  • Google Compute instance receiving email
  • Immutability and synchronization in Java
  • Remove stopwords and tolower function slow on a Corpus in R
  • Dynamically run java code with Process
  • UIScrollView does not restore properly
  • Pick Out Specific Number from Array? [duplicate]
  • Multiple table join MySQL multiple foreign keys
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • Stop an element moving with padding on hover
  • time column in sqlite using gorm
  • Ajax call on Multiple selection in Select box
  • How to define something in JavaScript [closed]
  • Neo4j…how to get a visual representation of my data?
  • I am consuming a WCF service that requires headers from a .NET 2 website. How can I programmatically
  • How can I ssh into a server that requires 2 password authentication using python's paramiko mod
  • Bitrate JWplayer
  • Make checkout phone field optional for specific countries in WooCommerce
  • calling IO Operations from thread in ruby c extension will cause ruby to hang
  • Angular 4: Responsive Grid List
  • Accessing Arguments, Workflow Variables from custom activities
  • Firebase: How to read from external DB?
  • Write to .csv file with PHP (Commas in Data Error)