After 1/2 year API 403 error

Bonagura Marcello 30 Reputation points
2024-05-28T12:31:31.4833333+00:00

I have a PowerShell script that runs daily and creates a folder in the employee contact lists via token (request) and writes the company's contacts in it so that everyone has them on their cell phone. The next day, this folder is deleted and the contacts are rewritten. This has now worked wonderfully for six months.

Now it suddenly no longer works if the folder already exists. That is, it Invoke-RestMethod. It can no longer delete it (Error 403). But with one user it works about 95%, all other 42 do not work. I don't understand why? It makes no sense! Why for this user, but not for all the others?

The script continues to run without problems if you manually delete the contact folder.

I checked all permissions, made new API and gave much more permissions, manually connected, renamed folders, etc. No results.

The approximate procedure is as follows:

Request Access Token:

Invoke-RestMethod $url4Token -Method 'POST' -Headers $Headers4Token -Body $Body4Token

 

Delete contact folder:

Invoke-RestMethod $url -Method 'DELETE' -Headers $headers -Body $body

 

Create contact folder:

Invoke-RestMethod $url -Method 'POST' -Headers $headers -Body $body

 

Write in a loop all contacts fetched from AD (by Json)

Invoke-RestMethod $url -Method 'POST' -Headers $headers -Body $json

If you need any information, please just let me know. I will try my best.

Thanks for any help.

Outlook | Windows | Classic Outlook for Windows | For business
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
{count} vote

Accepted answer
  1. Thomas Starup 75 Reputation points
    2024-11-14T10:38:34.2866667+00:00

1 additional answer

Sort by: Most helpful
  1. Thomas Starup 75 Reputation points
    2024-09-16T12:45:07.7866667+00:00

    Any news - ?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.