HTTP 403 Forbidden error for getchanges SharePoint REST API call

%3CLINGO-SUB%20id%3D%22lingo-sub-189364%22%20slang%3D%22en-US%22%3EHTTP%20403%20Forbidden%20error%20for%20getchanges%20SharePoint%20REST%20API%20call%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-189364%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I'm%20new%20to%20sharepoint%20and%20stuck%20with%20the%20below%20issue%3A%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3EObjective%3A%20To%20query%20for%20changes%20(updated%20or%20deleted%20list%20items)%20from%20Sharepoint%20online%20sites%20using%20REST%20API%20from%20a%20C%23%20Console%20application.%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EI%20tried%20to%20construct%20below%20URL%20using%20HTTP%20Post%3A%3C%2FP%3E%3CP%3Ehttps%3A%2F%2F%3CSTRONG%3Esite1%3C%2FSTRONG%3E.sharepoint.com%2F%3CSTRONG%3E_api%2Fweb%3C%2FSTRONG%3E%2Fgetchanges%3C%2FP%3E%3CP%3EAnd%20the%20item%20payload%20is%20passed%20as%20follows%3A%3C%2FP%3E%3CPRE%3E%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3Evar%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20itemPayload%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Equery%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20__metadata%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Etype%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E%22SP.ChangeQuery%22%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7D%2C%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22typ%22%3EUpdate%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3Etrue%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EItem%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3Etrue%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%7D%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EThe%20above%20code%20works%20fine%20for%20%22%3CSTRONG%3Esite1%3C%2FSTRONG%3E%22%2C%20however%2C%20when%20I%20try%20the%20same%20for%20%22site2%22%2C%20which%20has%20bunch%20of%20sub%20sites%20under%20site%20collection%20like%20below%3A%3C%2FP%3E%3CP%3Ehttps%3A%2F%2F%3CSTRONG%3Esite2%3C%2FSTRONG%3E.sharepoint.com%2F%3CSTRONG%3Esites%2Fcustomer1%3C%2FSTRONG%3E%2F_api%2Fweb%2Fgetchanges%3C%2FP%3E%3CP%3EI'm%20getting%20403%20forbidden%20error%20as%20response%3A%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EStatusCode%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22lit%22%3E403%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22typ%22%3EReasonPhrase%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E'FORBIDDEN'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22typ%22%3EVersion%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22lit%22%3E1.1%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22typ%22%3EContent%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E..%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EHowever%2C%20when%20I%20tried%20ChangeQuery%20using%20CSOM%20library%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ethe%20call%20works%20fine%3C%2FSTRONG%3E.%20I%20am%20passing%20the%20same%20user%20credentials%20for%20both%20REST%20query%20and%20CSOM.%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20leads%20to%20my%20question%20whether%20my%20user%20credential%20require%20any%20special%20%22permission%22%20to%20get%20%22changes%22%20using%20REST%20(or)%20whether%20I'm%20doing%20anything%20wrong%20with%20my%20approach.%3C%2FP%3E%3CP%3EI%20looked%20into%20other%20forum%20posts%2C%20but%20I%20could%20not%20find%20out%20solutions%20similar%20to%20site2.%3C%2FP%3E%3CP%3EKindly%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-189488%22%20slang%3D%22en-US%22%3ERe%3A%20HTTP%20403%20Forbidden%20error%20for%20getchanges%20SharePoint%20REST%20API%20call%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-189488%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Juan%2C%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20reply.%20Our%20team's%20view%20is%20that%20if%20we%20build%20our%20product%20using%20REST%20API%2C%20we%26nbsp%3Bcan%20be%20flexible%20to%20adopt%20to%20different%20environments%20and%20also%20avoid%26nbsp%3Bdependencies%20on%20specific%20sharepoint%20assemblies%20(like%20Microsoft.SharePoint.Client.dll%20)%20.%26nbsp%3BIf%26nbsp%3BI%20cannot%20resolve%20my%20ChangeQuery%20call%20using%20REST%2C%20then%20we%20would%20go%20for%20CSOM.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3Esenthil%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-189439%22%20slang%3D%22en-US%22%3ERe%3A%20HTTP%20403%20Forbidden%20error%20for%20getchanges%20SharePoint%20REST%20API%20call%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-189439%22%20slang%3D%22en-US%22%3EOut%20of%20curiosity%3A%20why%20do%20you%20want%20to%20use%20RET%20API%20in%20your%20console%20application%3F%20With%20CSOM%20you%20are%20going%20to%20be%20much%20more%20productive%20and%20get%20the%20data%20you%20need%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi, I'm new to sharepoint and stuck with the below issue:

Objective: To query for changes (updated or deleted list items) from Sharepoint online sites using REST API from a C# Console application.

I tried to construct below URL using HTTP Post:

https://site1.sharepoint.com/_api/web/getchanges

And the item payload is passed as follows:

     var itemPayload = new {query = new { __metadata = new {type ="SP.ChangeQuery" },
Update=true,Item=true } };

The above code works fine for "site1", however, when I try the same for "site2", which has bunch of sub sites under site collection like below:

https://site2.sharepoint.com/sites/customer1/_api/web/getchanges

I'm getting 403 forbidden error as response:

{StatusCode: 403, ReasonPhrase: 'FORBIDDEN', Version: 1.1, Content: ..}

However, when I tried ChangeQuery using CSOM library, the call works fine. I am passing the same user credentials for both REST query and CSOM.

This leads to my question whether my user credential require any special "permission" to get "changes" using REST (or) whether I'm doing anything wrong with my approach.

I looked into other forum posts, but I could not find out solutions similar to site2.

Kindly help.

2 Replies
Highlighted
Out of curiosity: why do you want to use RET API in your console application? With CSOM you are going to be much more productive and get the data you need
Highlighted

Hello Juan,

Thank you for your reply. Our team's view is that if we build our product using REST API, we can be flexible to adopt to different environments and also avoid dependencies on specific sharepoint assemblies (like Microsoft.SharePoint.Client.dll ) . If I cannot resolve my ChangeQuery call using REST, then we would go for CSOM. 

 

Thanks,

senthil