none
Does SharePoint 2013 support application/json Accept header without specifying odata=verbose?

    Question

  • When I am testing APIs in SharePoint 2013, it seems like the REST APIs only support setting application/json;odata=verbose in Accept header if I want the API to return response in json format, if I set application/json without odata=verbose then the response will be in xml format. But in SharePoint 2016 it supports both application/json;odata=verbose and application/json, and the response of application/json only has simplified information comparing to the response with odata=verbose. My question is does SharePoint 2013 only support application/json;odata=verbose in Accept header? Anyway in most cases we don't need all the informations in response.

    Regards,

    Xifeng

    Monday, March 12, 2018 10:05 AM

Answers

  • Hi,

    REST API can't provide this feature, we have to run PowerShell script in SharePoint server.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by zxfchris Wednesday, March 14, 2018 1:42 AM
    Tuesday, March 13, 2018 10:00 AM
    Moderator

All replies

  • Yes, SharePoint 2013 Only accept Application/json or else it will send XML as response. however, you can tweak the Odata value as below.

    accept: application/json; odata=minimalmetadata

    This is the middle ground. You’ll get some metdata, and you’ll also need to send some, but it’s less.

    accept: application/json; odata=nometadata

    This option means we won’t get any metadata and we also don’t have to send any.

    accept: application/json

    If you don’t specify the odata setting at all, it will default to odata=minimalmetadata.

    You can use these settings both on the inbound and outbound part of your REST calls.

    Content-Type: "accept: application/json; odata=minimalmetadata"

    means that you are sending data that contains minimal metadata.

    Likewise,

    Accept: "accept: application/json; odata=verbose"

    Please read below article for more information in this regard

    http://sympmarc.com/2016/05/02/making-your-rest-calls-simpler-by-changing-the-metadata-setting/


    Ramakrishnan


    Please remember to mark the replies as answers if they helped.

    Monday, March 12, 2018 2:38 PM
  • Hi,

    We can turn on the multiple metadata formats for JSON in SharePoint Server 2013 using the PowerShell below:

    $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"
    

    More information is here:

    How to turn on and off the multiple metadata formats for JSON in SharePoint Server 2013

    https://technet.microsoft.com/en-us/library/dn762092(v=office.15).aspx

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Tuesday, March 13, 2018 7:34 AM
    Moderator
  • Thanks for your answer, Dennis.

    So running Powershell script is the only way to turn on/off this feature and this can not be complished from REST API is it? If this can be done by runing application code then it'll be great.

    Regards,

    Xifeng

    Tuesday, March 13, 2018 9:46 AM
  • Hi,

    REST API can't provide this feature, we have to run PowerShell script in SharePoint server.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by zxfchris Wednesday, March 14, 2018 1:42 AM
    Tuesday, March 13, 2018 10:00 AM
    Moderator