After 1/2 year API 403 error

Bonagura Marcello 5 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
Outlook
A family of Microsoft email and calendar products.
3,432 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,457 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,337 questions
{count} vote