Issue with Forbidden Error When Updating BookingBusiness in Graph API

Marco de Jong 0 Reputation points
2024-11-26T07:50:08.55+00:00

I am trying to update a booking business using the Graph API in C#. I can retrieve my booking business without any issues. However, when attempting to update this booking business, I receive a "Forbidden" (403) error, even though the changes are applied. The documentation indicates that a successful update should return "HTTP/1.1 204 No Content."

I have set up the permissions as specified in the documentation:
Update a booking business.

Here is a snippet of my code:

// Get the booking business to update
var bookById = await graphClient.Solutions.BookingBusinesses["booking@bookings.tenant.nl"].GetAsync();

// Only change the phone number for now
bookById.Phone = "xxx-xxxxxxxx";
 
// Patch the booking business
var patchResult = await graphClient.Solutions.BookingBusinesses["booking@bookings.tenant.nl"].PatchAsync(bookById); 

Is this a known problem, or is there something I might be missing?

Regards,
Marco

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,464 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,095 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,575 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 3,465 Reputation points Microsoft Vendor
    2024-11-26T08:38:37.3966667+00:00

    Hello Marco de Jong,

    Thank you for contacting for Microsoft Support!

    It sounds like you're encountering a permissions issue. Here are a few things you might want to check:

    1. Permissions: Ensure that the permissions granted to your application include Bookings.ReadWrite.All , Bookings.Manage.All for updating booking businesses. Sometimes, even if permissions are set, they might not be correctly applied or consented to.
    2. Token Type: Verify that the access token you're using matches the permissions granted. If you're using delegated permissions, ensure the token is acquired through a user context. For application permissions, ensure you're using the client credentials flow.
    3. Admin Consent: Make sure that the permissions have been granted admin consent. Without admin consent, some permissions might not be fully effective.

    If you've checked all these and the issue persists, it might be helpful to decode your access token using a tool like jwt.ms to ensure it contains the correct permissions and claims.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


  2. Yakun Huang-MSFT 7,120 Reputation points Microsoft Vendor
    2024-11-26T09:18:37.2466667+00:00

    Hello Marco de Jong,

    Thank you for reaching out to Microsoft Support!

    The documentation mentions that the request body provides only the property values that need to be updated, whereas your code provides all the properties of the entire BookingBusinesses object. It is therefore recommended that you create a new request body, as shown below:

    User's image

    // Code snippets are only available for the latest version. Current version is 5.x
    // Dependencies
    using Microsoft.Graph.Models;
    var requestBody = new BookingBusiness
    {
    	Phone = "xxx-xxxxxxxx"
    };
    // To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
    var result = await graphClient.Solutions.BookingBusinesses["{bookingBusiness-id}"].PatchAsync(requestBody);
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


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.