Forum Widgets
Latest Discussions
Failed to get FormDigestValue with 403 Forbidden in java
Hello Everyone, This is my first time to access sharepoint via java in my project. I used AI to get varies of java code and try to connect to sharepoint to get FormDigestValue as step one (The target is to upload files). Somehow it always return 403. Could you please help to figure out the root cause? I appreciate for any comments. I struggle with the problem for several days already. Code 1: System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); URL urlRequest = new URL(siteUrl + "/_api/contextinfo"); HttpURLConnection contextInfoRequest = (HttpURLConnection) urlRequest.openConnection(); contextInfoRequest.setRequestProperty("Content-Type", "application/json;odata=verbose"); contextInfoRequest.setRequestProperty("Accept", "application/json;odata=verbose"); contextInfoRequest.setRequestProperty("Connection", "Keep-Alive"); contextInfoRequest.setRequestProperty("Content-Length", "0"); contextInfoRequest.setDoOutput(true); contextInfoRequest.setRequestMethod("POST"); String authStr = username + ":" + password; String encodedAuthStr = Base64.getEncoder().encodeToString(authStr.getBytes()); contextInfoRequest.setRequestProperty("Authorization", "Basic " + encodedAuthStr); contextInfoRequest.connect(); InputStream in = contextInfoRequest.getInputStream(); -- 403 here Code 2: System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); URL urlRequest = new URL(siteUrl + "/_api/contextinfo"); HttpURLConnection contextInfoRequest = (HttpURLConnection) urlRequest.openConnection(); contextInfoRequest.setRequestProperty("Content-Type", "application/json;odata=verbose"); contextInfoRequest.setRequestProperty("Accept", "application/json;odata=verbose"); contextInfoRequest.setRequestProperty("Connection", "Keep-Alive"); contextInfoRequest.setRequestProperty("Content-Length", "0"); contextInfoRequest.setDoOutput(true); contextInfoRequest.setRequestMethod("POST"); Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(domain + "\\" + username, password.toCharArray()); } }); contextInfoRequest.connect(); InputStream in = contextInfoRequest.getInputStream(); -- 403 here Code 3: // Create the SharePoint context HttpClient client = createHttpClient(); String authHeader = getBasicAuthHeader(shareac, sharepw); // Example request to SharePoint HttpRequest request = HttpRequest.newBuilder().uri(URI.create(galurl + "/_api/contextinfo")) .header("Authorization", authHeader) .header("Accept", "application/json;odata=verbose") .POST(HttpRequest.BodyPublishers.ofString("")) .build(); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Response Status Code: " + response.statusCode()); -- 403 here Code 4: // 设置SSL协议 SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(null, null, null); HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); // 创建HttpClient CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(galurl, -1, AuthScope.ANY_REALM), new UsernamePasswordCredentials(shareac, sharepw)); CloseableHttpClient httpClient = HttpClients.custom() .setDefaultCredentialsProvider(credentialsProvider) .build(); // 使用httpClient进行请求 // 示例:发送GET请求 HttpGet httpget = new HttpGet(galurl); HttpResponse response = httpClient.execute(httpget); // 处理响应 int statusCode = response.getStatusLine().getStatusCode(); System.out.println("Response status code: " + statusCode); -- 403 hererickyhuang2025Mar 31, 2025Copper Contributor20Views0likes0CommentsHow to get list items from one SharePoint tenant to another SharePoint tenant
Requirement: We have developed task management solution which can be deployed at any SharePoint site and I wanted to pull tasks from SharePoint site in different tenant to my tenant SharePoint site and show them in task dashboard. We have used SharePoint Framework (SPFx) to develop this dashboard, and we are ready to accommodate any other technology also if that fulfills requirement. Please suggest if this is possible to do and what should be approach? Thanks, DeepakDeepak1981Mar 26, 2025Copper Contributor21Views0likes0CommentsIssue with SharePoint Add-in Uninstalling After Renaming App Web url
We are migrating customers from the retired SharePoint Add-in model to the new SPFx model. As part of this, we automatically rename the App Web (created during Add-in installation) and changing its URL and create a new subsite with the original App Web’s name & URL to host the SPFx app and its content. However, when the customer later uninstalls the Add-in, SharePoint deletes the new subsite instead of the original App Web, which still exists under its renamed URL. This suggests that the installed Add-in is not aware of the App Web renaming/changed URL, causing it to target the wrong site for deletion. Our migration process relies on preserving existing links by maintaining the original App Web URL for the new subsite. Is there a way to update the installed Add-in to recognize the renamed App Web? Alternatively, is there a recommended approach to prevent the unintended deletion of the new subsite when the Add-in is uninstalled?Ross_CullenMar 21, 2025Copper Contributor24Views0likes0CommentsSharepoint automatically adds a trailing zero to a currency in a sharepoint list
Hi there, Furthur to earlier thread https://answers.microsoft.com/en-us/msoffice/forum/all/sharepoint-automatically-adds-a-trailing-zero-to-a/4e41e967-3268-4853-8805-19b682992794?page=1 I am from India and still facing same issue. I have tried all the workarounds provided in above thread but none worked. In my case the column is a calculated column with nested IF formula. A single IF statement takes only 19 conditions until than it calculates value also correctly. But anything above 19 conditions it throws a generic value as Zero with out syntax error. If I add the & operator it calculates the value but adds additional zeros before and after the numbers. Requesting help at the earliest as my project is stuck Regards, AvinashNash007Mar 06, 2025Copper Contributor12Views0likes0CommentsWebhooks for file permissions changes
Hey there! I am looking to receive a webhook from Sharepoint when permissions on a file or folder change. This doesn't seem like an explicit event in Sharepoint, but I did find this section in the docs: I've tested using this header a few times, but so far have not been able to receive the webhooks. Here is a cURL of my webhook setup request: curl --location 'https://graph.microsoft.com/v1.0/subscriptions' \ --header 'Authorization: Bearer [redacted]' \ --header 'Content-Type: application/json' \ --header 'prefer: includesecuritywebhooks' \ --data '{ "resource": "/drives/[drive_id]/root", "changeType": "updated", "notificationUrl": "[target_url\]", "expirationDateTime": "2025-03-03T21:15:14Z", }' Sharepoint responds with a 201, with the following response headers: "headers": { "User-Agent": "Mozilla/5.0", "Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Connection": "keep-alive", "Authorization": "[redacted]", "content-type": "application/json", "prefer": "includesecuritywebhooks", "Content-Length": "405" } So it does seem that the header was accepted. In terms of licenses, my Sharepoint instance is tied to a user with an E5 trial license, and a paid E3 license. I am still not receiving webhooks when permissions update on files. I do receive other webhooks (ie files changed, added etc), just not for a permission change event. Has anyone figured out how to use this header successfully? Thanks!mgongAPIMar 03, 2025Copper Contributor80Views0likes0CommentsAbnormal FileRef for document library file
Hi, we found an abnormal api behavior when attempting to get file with sharepoint api When we use sharepoint api https://ferociagroep.sharepoint.com/sites/****************/_api/Web/Lists(@lid)/Items(@iid)?@lid=guid%27****************%27&@iid=****************&$select=FileRef to get file, we found the FileRef as below: /sites/*******************/_vti_rb/0/19386/Berekening Inlenersbeloning en salaris/Berekening salaris Rishi Djairam .docx However, the site root is supposed to be /sites/*******************/document, instead of the _vti_rb, does anyone what is _vti_rb? Thank you, Best regards, Ethan FangethanfangFeb 13, 2025Copper Contributor28Views0likes0Comments401 unauthorised for ExecuteQuery in sharepoint CSOM
Hi, I am trying to connect the sharepoint site with client id and secret but getting 401 unauthroised error while hitting the executequery() method. While doing app registrations both Microsoft graph and share point API permissions with full site control has been given including trusted the app through appinv.aspx. Still getting 401 unauthorised error. Since ACS is retiring, do we need to follow any other permissions for share point level site access. The same execute query is working fine for client id, certificate combination. But not working for client id and secret. static void Main(string[] args) { var authManager = new AuthenticationManager("***************************", "C:\\Program Files\\OpenSSL-Win64\\bin\\certificate.pfx", "*******", "********.onmicrosoft.com"); using (var cc = authManager.GetContext("https://****.sharepoint.com/sites/****")) { cc.Load(cc.Web, p => p.Title); cc.ExecuteQuery(); Console.WriteLine(cc.Web.Title); ListCollection listCollection = cc.Web.Lists; cc.ExecuteQuery(); // this is working fine }; // Replace with your SharePoint Online details string siteUrl = "****************************"; string tenantId = "***************************"; string clientId = "********************************"; string clientSecret = "******************************"; // App secret try { using (var context = GetClientContextWithOAuth(siteUrl, tenantId, clientId, clientSecret)) { // Example: Retrieve web title Web web = context.Web; context.Load(web, w => w.Title); context.ExecuteQuery(); // this is throwing 401 unauthorized error Console.WriteLine("Connected to: " + web.Title); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } } private static ClientContext GetClientContextWithOAuth(string siteUrl, string tenantId, string clientId, string clientSecret) { // Azure AD OAuth 2.0 endpoint string authority = $"https://login.microsoftonline.com/*******************"; // Use MSAL to acquire an access token var app = ConfidentialClientApplicationBuilder.Create(clientId) .WithClientSecret(clientSecret) .WithAuthority(new Uri(authority)) .Build(); var authResult = app.AcquireTokenForClient(new[] { $"{siteUrl}/.default" }).ExecuteAsync().Result; if (authResult == null) { throw new Exception("Failed to acquire the access token."); } // Use the access token to authenticate the ClientContext var context = new ClientContext(siteUrl); context.ExecutingWebRequest += (sender, e) => { e.WebRequestExecutor.WebRequest.Headers["Authorization"] = "Bearer " + authResult.AccessToken; }; return context; }dhanushaelangovanFeb 12, 2025Copper Contributor59Views0likes0CommentsManaged metadata showing up randomly in lists (might be PnP Provisioning related)
Dear people, I have SharePoint sites with a lot of lists each containing a couple of managed metadata columns. The sites are defined in a template and get rolled out via PnP provisioning. I did that many times before and never had this: The lists show a weird behavior: some items get randomly the value of a specific managed metadata (it's always the same). None of the columns have set a default value. All lists have only list content types - no site content types. The lists where the metadata shows up don't even have a column where this metadata is set. I was suspecting the -1 setting in the default value in the columns to connect to the Hidden Taxonomy List so I removed all default values. But the issue persists. Has anyone ever experienced this? Thank y'all!Maj-JacobJan 30, 2025Copper Contributor32Views0likes0CommentsIn SharePoint we have "Everyone except external users" AD Group but can't be synced by SCIM
We are using SharePoint online and SharePoint server 2016, 2019, subscription edition and we are seeing some issues and Azure AD. I have synced a customer's Azure AD using SCIM . Also synced SharePoint site in a SharePointCustomApp that we have using SharePoint APIs. Now for SharePoint we get pages with ACL for groups and one of the group's name is "Everyone except external users". All the pages have groups associated and they are federated from Azure AD and we found all groups. However "Everyone except external users" group cannot be synced via IDC SCIM protocol. Other groups we are able to sync properly(can get its members). Our other customers are also facing same issue for this "Everyone except external users" group. We need this group ("Everyone except external users") also to return proper members.yname2480Jan 27, 2025Copper Contributor27Views0likes0CommentsPrevent Automatically Opening the File Explorer on the Upload Tab (filepicker)
I am working on an application customizer that will inject custom UI into the File Picker's Upload tab. Because of this, I want to prevent the file explorer from automatically opening when the user clicks on the Upload tab. I’ve tried several methods to achieve this by manipulating the DOM through my custom code in the application customizer. I even tried removing the "file" input element from my custom code. However, the file explorer still opens automatically when the user clicks on the Upload tab. Is there any way to prevent this?addindeveloper1Jan 21, 2025Copper Contributor14Views0likes0Comments
Resources
Tags
- developer1,229 Topics
- PnP646 Topics
- apis483 Topics
- Extensibility251 Topics
- Responsive128 Topics
- hybrid81 Topics
- SPFx70 Topics
- SharePoint Online64 Topics
- powershell23 Topics
- CSOM15 Topics