1

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?

3 Answers 3

7

Try this:

"accept": "application/json; odata=verbose"
1
  • yes, adding odata=verbose worked. but I want to use application/json only. Looks like I need to run some powershell scripts as per above comment.
    – Joe
    Commented Apr 6, 2018 at 5:52
2

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"
13
  • Hi Swerve, thanks for the reply. Yes I would like to use application/json only. I went through the link shared by you "The solution is now posted to Technet" and Technet link redirecting me to microsoft forum page with heading "Administration of SharePoint Server". Please guide.
    – Joe
    Commented Apr 6, 2018 at 5:58
  • Sorry about that. I have edited the post with a direct link for what you need.
    – Swerve
    Commented Apr 6, 2018 at 19:07
  • Hi Swerve, I downloaded and installed WCF Data Services 5.6. But I see no changes in API behavior. JSON Minimal and nometadata still not working for me. I read blog as suggested. I think I have not run step "JSON.ps1 to update web.config". Could you please suggest from where I can download and follow instruction to install this ps1?
    – Joe
    Commented Apr 9, 2018 at 6:23
  • Hi Swerve, I went through social.msdn.microsoft.com/Forums/office/en-US/… and ran powershell script, but no luck.
    – Joe
    Commented Apr 10, 2018 at 6:38
  • Sorry for the trouble Joe. I have now shared the PowerShell that we use to allow for the usage of application/json in the Accept header after upgrading WCF Data Services to 5.6.
    – Swerve
    Commented Apr 10, 2018 at 20:08
1

Change this
headers: { "accept": "application/json", },

Try This headers: { "accept": "application/json;odata=verbose", },

1
  • Hi Ganesh, I dont want to use odata=verbose. I would like to use "application/json" only. We would required to run some powershell scripts to enable it.
    – Joe
    Commented Apr 6, 2018 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.