Query
3 Topics401 (Unauthorized) When calling Sharepoint Query
Hello everyone, I am currently getting this error 401 when I try to call my Sharepoint Endpoint. It occurred after I added the following below into the header. What is the issue here? GET http://www.test.com/Shared%20Documents/query%20result%20BEFORE.xml 401 (Unauthorized) Previously, I was facing this error: Access to XMLHttpRequest at **** from origin 'http://127.0.0.1:1234' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. I added the Access-Control-Allow-Origin with a value of "*" in the HTTP Response Headers and now I am getting the 401 error. Please do help! Thank you!12KViews0likes3CommentsSharepoint CORS Policy issue persist even after ISS Configurations
I am currently trying to fetch my Sharepoint API via my code. However I am running into the issue below. I have already enabled the ISS Configurations as shown in the link below. However, the issue still persist. https://techcommunity.microsoft.com/t5/iis-support-blog/access-to-xmlhttprequest-from-origin-has-been-blocked-by-cors/ba-p/3800362 Error: index.html:1 Access to XMLHttpRequest at 'http://testing- sharepoint/Shared%20Documents/query%20result%20BEFORE.xml' from origin 'http://127.0.0.1:2233' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. My code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { function apiCallTest(searchValue) { const adminAccount = 'testUser'; const adminAccountPassword = 'testPassword'; const auth = btoa(`${adminAccount}:${adminAccountPassword}`); const testQuery = 'BEFORE'; const apiUrl= "http://testing-sharepoint/Shared%20Documents/query%20result%20BEFORE.xml" const headers = { 'Authorization': `Basic ${auth}`, // 'Accept': 'application/json;odata=nometadata', // 'Content-Type':'application/json', // 'Access-Control-Allow-Credentials':'TRUE', // 'Access-Control-Allow-Headers':'Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization', // 'Access-Control-Allow-Origin':'*', // 'Access-Control-Allow-Methods':'GET,POST,PUT,OPTIONS' }; $.ajax({ url: apiUrl, headers: headers, method: 'GET', dataType: 'xml', success: function(data) { // Process the search results as needed console.log('Search Results:', data) }, error: function(xhr, textStatus, errorThrown) { console.log("Cannot connect") console.error('Error:', xhr, textStatus, errorThrown); } }); } function checkConnection(url) { if (navigator.onLine) { console.log(`You are online. Checking connection to ${url}...`); // You can attempt further actions here if needed } else { console.log('You are offline. Check your network connection.'); } } checkConnection("https://testing-sharepoint/_api/site"); apiCallTest(); }); </script> </head> <body style="background: black; color: aliceblue; font-size: 2rem;"> </body> </html>1.5KViews0likes0CommentsHow to get links of some Sharepoint Query to a central place
I am facing an interesting problem. For an application, I need to collect links (and some metadata/properties: year, company_division, type and date_document_modified) from a large number of Sharepoint sites based on some query mechanism, and subsequently put them in a Sharepoint list at a central location on some central Sharepoint site. Connected to this Sharepoint list will be a Logic App that has a trigger task of ‘when an item is created or modified’ on this list. Note that the ability to use of LogicApp on a list of links is a must in the solution, sadly I’m bound to this, and thus not looking for alternative solutions. To do so, I want to query the whole of a certain Sharepoint environment where I want to i.e. get all document urls, year, company_division, type and the date_document_modified for a query like ‘type:"notes" company_division:"division1" year:”2020”’, and get these properties automatically transferred to a list based on this query. Is there a possibility to do this from just the general Sharepoint GUI? So the flow is: Query -> Results -> Output to some Sharepoint list. If no, is there a programmatic way to achieve this kind of solution (I would much rather prefer a non-programmatic and simplistic way though)? Output in the list would have to look basically like this: document_url type company_division year date_document_modified url1 notes division1 2020 22-09-2022 url2 notes division1 2020 22-09-2022 Also, I would like to be able to automatically schedule the Sharepoint query to run once every X days in some way or another (preferably using the Sharepoint GUI, but otherwise maybe with PowerAutomate or something). With this, I would also – if possible – like to be able to modify list elements, for example when a new entry is added that has the same url, type, company division and year, but has a new ‘date_document_modified’. Is there any way to achieve this without too much programmatic hassle and if not, are there programmatic ways to achieve such a scenario?615Views0likes0Comments