I’m not sure if this is by design but I’m struggling to find any information on it.
Using the SharePoint API I can get the value of “OData__ModerationStatus” in a list however via MS Graph API I cannot. For a few reasons I need to use the Graph API over the SharePoint API. Is there a solution to this?
Code example in Python (all GUIDs are replaced with random ones)
import requests
import json
def get_access_token(tenant_id, client_id, client_secret):
url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
body = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"scope": "https://graph.microsoft.com/.default",
}
response = requests.post(url, headers=headers, data=body)
access_token = response.json().get("access_token")
return access_token
def get_sharepoint_list_items(site_id, list_id, access_token):
url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json;odata=verbose",
"ConsistencyLevel": "eventual",
"Accept": "application/json;odata.metadata=full;odata.streaming=false;IEEE754Compatible=false",
}
# Explicitly request the OData__ModerationStatus field
params = {"$expand": "fields($select=Title,OData__ModerationStatus)"}
response = requests.get(url, headers=headers, params=params)
return response.json()
tenant_id = "60bbe459-5908-4897-861b-eba1a234d6b0"
client_id = "1c5f10c7-76fc-45b2-b0e4-2b5c0c3117a8"
client_secret = "abc123"
site_id = "<tenant_name>.sharepoint.com,fbbf72ba-ad20-4042-869c-3da2cad68250,f0c5770d-518c-4d3f-82e8-c1f294e3889e"
list_id = "58a86e43-a837-4118-83f5-18a321a550a5"
access_token = get_access_token(tenant_id, client_id, client_secret)
list_items = get_sharepoint_list_items(site_id, list_id, access_token)
with open("output.json", "w") as f:
json.dump(list_items, f, indent=4)