I am using SharePoint 2013 onprem and online version for integration purpose. While accessing REST APIs for online SharePoint, I was able to use application/json and application/xml as ACCEPT header with no issues.
However, while accessing SharePoint 2013 onpremise REST APIs I could use application/xml as ACCEPT header and using application/json throwing below error:
GET - http://xxxxxxx:8300/_api/web/
Header -
Accept:application/json
Response:
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
"message": {
"lang": "en-US",
"value": "The HTTP header ACCEPT is missing or its value is invalid."
}
}
}
Could you please suggest How can I get JSON response for LIST, LISTITEM objects?
Try this:
"accept": "application/json; odata=verbose"
I've encountered this type of issue before in on-premise SharePoint 2013. Mike's answer also has merit. You will need to change your Accept header value to "application/json;odata=verbose", though I don't think that is the issue. I think you need to patch the on-premise instance of SharePoint to support OData 3 and JSON Light. Read the instructions carefully from the following blog post. As we deploy solutions in the field, we still find farms that encounter this when we make requests for json from the REST API. However, you are far more likely to find it in a freshly spun up development instance. It's relatively quick and simple to address. Good Luck!
Edit:
It appears the Technet article was recently removed. Here is the download link for WCF Data Services 5.6. Still follow the guidance in original post and I think you'll be up and running pretty quickly. In addition, you should be able to drop off the odata=verbose portion of the Accept header after this update.
PowerShell To Complete the Upgrade (Run after the WCF Data Services Install)
Run this on the SharePoint Server that your upgraded WCF Data Services on.
$configOwnerName = "JSONLightDependentAssembly"
$spWebConfigModClass ="Microsoft.SharePoint.Administration.SPWebConfigModification"
$dependentAssemblyPath ="configuration/runtime/*[local-name()='assemblyBinding' and namespace-uri()='urn:schemas-microsoft-com:asm.v1']"
$dependentAssemblyNameStart ="*[local-name()='dependentAssembly'][*/#name='"
$dependentAssemblyNameEnd = "'][*/#publicKeyToken='31bf3856ad364e35'][*/#culture='neutral']"
$dependentAssemblyValueStart = "<dependentAssembly><assemblyIdentity name='"
$dependentAssemblyValueEnd ="' publicKeyToken='31bf3856ad364e35' culture='neutral' /><bindingRedirect oldVersion='5.0.0.0' newVersion='5.6.0.0' /></dependentAssembly>"
$edmAssemblyName ="Microsoft.Data.Edm"
$odataAssemblyName ="Microsoft.Data.Odata"
$dataServicesAssemblyName ="Microsoft.Data.Services"
$dataServicesClientAssemblyName ="Microsoft.Data.Services.Client"
$spatialAssemblyName ="System.Spatial"
$assemblyNamesArray = $edmAssemblyName,$odataAssemblyName,$dataServicesAssemblyName,$dataServicesClientAssemblyName, $spatialAssemblyName
Add-PSSnapin Microsoft.SharePoint.Powershell
$webService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
################ Adds individual assemblies ####################
For ($i=0; $i -lt 5; $i++)
{
echo "Adding Assembly..."$assemblyNamesArray[$i]
$dependentAssembly = New-Object $spWebConfigModClass
$dependentAssembly.Path=$dependentAssemblyPath
$dependentAssembly.Sequence =0 # First item to be inserted
$dependentAssembly.Owner = $configOwnerName
$dependentAssembly.Name =$dependentAssemblyNameStart + $assemblyNamesArray[$i] + $dependentAssemblyNameEnd
$dependentAssembly.Type = 0 #Ensure Child Node
$dependentAssembly.Value = $dependentAssemblyValueStart + $assemblyNamesArray[$i] + $dependentAssemblyValueEnd
$webService.WebConfigModifications.Add($dependentAssembly)
}
###############################################################
echo "Saving Web Config Modification"
$webService.Update()
$webService.ApplyWebConfigModifications()
echo "Update Complete"
Change this
headers:
{
"accept": "application/json",
},
Try This
headers:
{
"accept": "application/json;odata=verbose",
},
Related
I'm trying to automatize process using Logic Apps -> On-premises data gateway -> SAP system.
I think I have a problem with metadata or cache.
Scenario:
I stopped developing solution on Wednesday about 23 (it didn't work), I didn't change anything inside and started to work on Thursday (today) about 12. I had to remind myself what kind of bug it was so i ran this logic app and suddenly it worked fine. I've been using element [RFC] Call function in SAP in Logic Apps with input RFC parameters:
<ZFM_MGR_RFC xmlns="http://Microsoft.LobServices.Sap/2007/03/Rfc/">
<INVOICE_ID>#{outputs('Invoice')['InvoiceId']}</INVOICE_ID>
</ZFM_MGR_RFC>
ABAP FM:
IMPORTING
VALUE(INVOICE_DATE) TYPE STRING OPTIONAL
DATA: ls_test TYPE zasd_test.
ls_test-mandt = sy-mandt.
ls_test-dates = sy-datum.
ls_test-time = sy-timlo.
INSERT zasd_test FROM ls_test.
So... I decided to enhance my FM in ABAP with another importing parameters. I added for example CUSTOMER_NAME parameter (string) and input parameter in Logic Apps. Suddenly I have an error - there's my [RFC] Call function in SAP response:
{
"statusCode": 400,
"headers": {
"x-ms-request-id": "7c4b6579-956d-4816-b988-73ad72d2962e",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cache-Control": "no-store",
"Set-Cookie": "ARRAffinity=db497ba0020393419ac466ef860f11922d2080b57a6df974e13c227f651e3274;Path=/;HttpOnly;Secure;Domain=sap-gwc.azconn-gwc.p.azurewebsites.net,ARRAffinitySameSite=db497ba0020393419ac466ef860f11922d2080b57a6df974e13c227f651e3274;Path=/;HttpOnly;SameSite=None;Secure;Domain=sap-gwc.azconn-gwc.p.azurewebsites.net",
"x-ms-connection-gateway-object-id": "7ebb3fec-1964-41ff-b45b-b97e71c65616",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "Thu, 15 Jul 2021 21:37:41 GMT",
"Content-Length": "202",
"Content-Type": "application/json"
},
"body": {
"error": {
"code": "GeneralBadRequest",
"message": "Failed to process request. Error details: 'Parameter: 'CUSTOMER_NAME' not found in the function metadata.'.",
"target": ""
}
}
}
It looks like Logic Apps/On-premise gateway has metadata of function module saved somewhere and refresh it not very often. How can I change it?
Thanks in advance.
I found a solution. Inside On-premises data gateway in settings overlap there is "Restart right now" button. Everytime you change something inside configuration/source code of program you have to click this button.
Warning: restarting computer doesn't give the same result. You have to restart gateway manually.
PS If you don't use On-Premise SAP Gateway you can temporarily test your solution with copying one FM to another and running the 2nd one.
Scenario:
I have an Angular SPA and a SharePoint 2013, installed in separated servers. I would like to consume a SharePoint discussion board in my SPA, means I would like to use my customized UI to perform CRU(D) operations on the SharePoint discussion board.
Through some workarounds I already achieved this objective using the SP REST API, but unfortunately since REST API doesn't allow setting some parameters for the discussion board (in particular the ParentID) I am not really able to use REST API in a satisfactory way.
In order to make it possible to work through the REST API I had to change the configuration in the IIS of the SharePoint Server to rewrite the headers and allow the Cross-Domains Call. Moreover I pass as options in the http call the digest from the context info. As I said, the comunication works, I can create new discussions or replies, but these are malformed because the API itself doesn't offer the methods that I need, but just some workaround to post not-so-good-looking messages in the discussion board (for example the threading is completely lost).
With JSOM I am doing this (I simpliefied a bit):
createReply() {
let clientContext = new SP.ClientContext("otherserver.sharepoint.com");
let list = clientContext.get_web().get_lists().getByTitle("myDiscussionBoardName");
let discussionItem = list.getItemById(parentTopicId); //eg. parentTopicId === 10
let properties = {'Body': 'My Message'};
let messageItem = SP.Utilities.Utility.createNewDiscussionReply(clientContext, discussionItem);
for (var propName in properties) {
messageItem.set_item(propName, properties[propName])
}
messageItem.update();
clientContext.executeQueryAsync(() =>
{ console.log("Gotcha!", messageItem); },
(error: any) => { console.log('Request failed', error); });
}
But unfortunately I get a 401 error. My understanding would also be that I won't need to provide a digest, since JSOM should take care of it by itself, but I am not sure of this, nor I am aware of how I could provide the digest within a JSOM call.
Honestly this message is my last hope to get to the bottom of this. I actually am already planning to use different solutions, but I can't believe that a solution doesn't exist, in particular because using a local proxy (sp-rest-proxy, you may know it well if you develop angular application based on SP) the connection somehow works correctly.
check the below link and also I just put one the example from our code
http://sharepointsanjay.blogspot.com/2016/05/how-to-refresh-request-digest-token.html
var headers = {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose",
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
"X-HTTP-Method": "MERGE",
"If-Match": "*"
};
return $http({
headers: headers,
method: "POST",
url: url,
data: JSON.stringify(data)
}).then(complete, failed);
I found that graph API in Germany endpoint seems not to support
GET /users/<id>/mailFolders/delta
it returns
**400**
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "cf713386-f050-40b4-b987-43cc2384eade",
"date": "2017-12-12T07:13:10"
}
}
}
However it works fine at
GET /users/<id>/mailFolders
Thanks for help
I had been in the same trouble, but I resolved.
Your request to:
GET /users/<id>/mailFolders/delta
is not correct, I think.
I guess that this mail folder delta was made by you, doesn't it?
To specify a mail folder, you need to use folder id, not display name.
Though you might already get the folder id, you can get the folder id by sending a request
GET /users/<id>/mailFolders
Note: Actually, we can get folder_ids via powershell:
Get-MailboxFolderStatistics
cmdlet on Exchange. However, these folder_id are malformed in ms-graph request. So you need to use the id which you can get as described above.
My code calls the OneNote API to resolve a SharePoint Online site URL to a SiteCollectionId and SiteId. We get a bearer token, set the HTTP auth header and issue a GET request to:
https://www.onenote.com/api/v1.0/myorganization/sitecollections/FromUrl(url='https://mytenantxyz.sharepoint.com/sites/copynotesite')
For approx a week, it has been returning the expected response, similar to:
{
"#odata.context": "https://www.onenote.com:576/api/v1.0/$metadata#Microsoft.OneNote.Api.SiteMetadata",
"siteCollectionId": "111e03ac-468c-4a28-9aab-543098ef49bb",
"siteId": "555d72a0-f82f-4e4c-ae8a-17ef0ea04f32"
}
However, today it has decided to return the following in approx 9 out of 10 requests:
{
error": {
"code" : “20158”,
"message": "Unable to get SiteMetadta for the url specified in the request.",
"#api.url": "http://aka.ms/onenote-errors#C20158"
}
}
The Microsoft docs (link) explain error 20158 as:
"Unable to get metadata for the site URL specified in the request. Check the format of the supplied URL. Supported formats include https://domain.sharepoint.com/site-a and https://domain.com/sites/site-a. (SharePoint support is in Preview.)"
I was unaware that this was in preview any more (I thought it was GA), but anyway it doesn't explain why it intermittently works for exactly the same input (same URL and bearer token).
Could it just be a bug in the OneNote API or SharePoint API that it must call under the covers?
Please refer to the blog - http://blogs.msdn.com/b/onenotedev/archive/2015/06/11/and-sharepoint-makes-three.aspx
We added the FromUrl method so you can pass in an absolute site URL and get the site collection and site IDs. You should make this call only when needed, and then store the values (site collection and site IDs) for future use in your requests to the OneNote API.
this however does not answer intermittency. Please share the X-correlationId header with us for a failing request so that we can help further.
I'm just in the process of experimenting with the Azure rest api's in preparation for some work I'm heading into...
Within node.js I'm trying to obtain a list of webspaces hosted by my subscription using the following code...
var websiteOptions = {
hostname: 'management.core.windows.net',
path: '/<<Subscription-ID>>/services/webspaces',
method: 'GET',
pfx: new Buffer(managementCert, 'base64'),
strictSSL: true,
headers: {
'x-ms-version': '2013-06-01'
}
};
websiteOptions.agent = new https.Agent(websiteOptions);
var request = https.request(websiteOptions,function(res){
console.log('Status Code:', res.statusCode);
console.log('Headers:', res.headers);
When executed it returns back with..
<Error xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Code>AuthenticationFailed</Code>
<Message>The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
</Message>
</Error>
The strange thing is that if I replace ..
/<<subscription-ID>>/services/webspaces
with...
/<<subscription-ID>>/services/hostedservices
That specific call works like a charm, returning a list of hosted services - so this leads me to believe that I'm encoding/attaching my management certificate correctly.
I have tried various api versions in the headers without much luck, I have also read various sections of this article without much luck.
So why are my credentials working in one section of the API and not the websties section
What am I missing, I'm sure it's something really simple :|
OK so now I feel daft, and it just goes to show that even big companies can get it wrong..
I have been playing a bit more and decided to drop a forward slash onto the end of the API call for the web spaces endpoint.. and...
Bingo... it worked like a treat!!!
Would have been nice if Microsoft was consistent across it's API endpoints, the hosted services end point for instance didn't need this trailing slash.
Also, accurate error messages would have been nice too, instead of just reporting an invalid credentials exception!!!
As always.. the simple things in life :(