After 1/2 year API 403 error

Bonagura Marcello 10 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.
4,002 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,266 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,592 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Thomas Starup 0 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.