googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.72k stars 2.41k forks source link

Why does google resource calendar turn into an unavailable room when I create it with its API? #2007

Open agn-7 opened 1 year ago

agn-7 commented 1 year ago

I posted the following question on StackOverflow as well without any response yet. That's why I decided to raise that here as well:

I'm going to create a google resource calendar room via its API (i.e. https://admin.googleapis.com/admin/directory/v1/customer/my_customer/resources/calendars). But the problem is, when I create one, it turns into an unavailable (crossed out) room within google calendar rooms and I couldn't find any attribute to make it available!

Here's the body request/response:

{
  "kind": "admin#directory#resources#calendars#CalendarResource",
  "etags": "\"CTyc505ppdmJR2motHVsU17kzItOkPo5vYViqlSF0rU/FB0b765ZgWIpTBaxn5YQIwZWWNM\"",
  "resourceId": "9f698cdc-84f9-4688-95a7-c2207b4fa7ae",
  "resourceName": "StackOverflow Test",
  "generatedResourceName": "Orangery Hildesheim Nordstadt-EG-StackOverflow Test (3)",
  "resourceEmail": "c_1881d77mmcaqsihgi426fseae6vnc@resource.calendar.google.com",
  "capacity": 3,
  "buildingId": "Orangery-Hildesheim-Nordstadt",
  "floorName": "EG",
  "resourceCategory": "CONFERENCE_ROOM"
}

Here's the output on google calendar:

enter image description here

aria1991 commented 1 year ago

@agn-7 Were you able to set the "status" attribute to"active" when creating the resource? if not I suggest you take these steps :

1- Send a PATCH request to the API endpoint with the updated status value in the request body. For example:


PATCH https://admin.googleapis.com/admin/directory/v1/customer/my_customer/resources/calendars/9f698cdc-84f9-4688-95a7-c2207b4fa7ae

Request Body:

{
"status": "ACTIVE"
}

You may also need to include any other required headers, such as an authorization token.

Alternatively, you might want to try creating the calendar resource with the "status" attribute set to "ACTIVE" in the initial request. This would make the calendar resource active immediately upon creation.

agn-7 commented 1 year ago

Hi, @aria1991 thank you for your response.

But the proposed method doesn't work! I added the "status": "ACTIVE" into the body of creating a new resource as follows without any result:

{
  "kind": "admin#directory#resources#calendars#CalendarResource",
  "etags": "\"CTyc505ppdmJR2motHVsU17kzItOkPo5vYViqlSF0rU/FB0b765ZgWIpTBaxn5YQIwZWWNM\"",
  "resourceId": "9f698cdc-84f9-4688-95a7-c2207b4fa7ae",
  "resourceName": "StackOverflow Test",
  "generatedResourceName": "Orangery Hildesheim Nordstadt-EG-StackOverflow Test (3)",
  "resourceEmail": "c_1881d77mmcaqsihgi426fseae6vnc@resource.calendar.google.com",
  "capacity": 3,
  "buildingId": "Orangery-Hildesheim-Nordstadt",
  "floorName": "EG",
  "resourceCategory": "CONFERENCE_ROOM",
  "status": "ACTIVE"  # NOTE
}

I also haven't seen that key value in the documentation!

aria1991 commented 1 year ago

Hi @agn-7 Let's try two different approaches:

1- Could you please change the last section of the code you posted above to :


"
resourceCategory": "CONFERENCE_ROOM",
"featureInstances": [
{
"feature": "resourceCalendarAvailability",
"value": "AVAILABLE"
}
]
}

And see whether you see any changes ?

2- If the first approach didn't work, Could you please let me know what you'll get as an output by running the code below( you need to replace the access_token variable with your actual token and the room_id variable with the actual id of the room you want to make available)

import requests

# Replace with your own access token
access_token = 'YOUR_ACCESS_TOKEN'

# Replace with the resource calendar room's unique ID
room_id = '9f698cdc-84f9-4688-95a7-c2207b4fa7ae'

# Set the room's status to "available"
data = {
    "status": "available"
}

# Build the API request
headers = {
    'Authorization': 'Bearer ' + access_token
}
url = f'https://admin.googleapis.com/admin/directory/v1/customer/my_customer/resources/calendars/{room_id}'
response = requests.patch(url, json=data, headers=headers)

# Print the API response
print(response.json())
agn-7 commented 1 year ago

@aria1991

The first approach didn't work either.

What actually is room_id? I have no room_id! Is it the same with buildingId?

agn-7 commented 1 year ago

@aria1991

I also created a new building with the mentioned extra key value (i.e. "status": "available") and used that buildingId for creating a new resource. But still, the problem is the same.

agn-7 commented 1 year ago

After two months finally I found a solution!

In fact, the main problem is related to the lack of permission for those created resources for other users in the organization. To tackle this problem I used another google API named ACL (Access Control Level) ref, to set a privilege for other users. Basically, a google resource actually is a google resource calendar, so you can use ACL API to access that calendar. Moreover, the parameter to reach that calendar is resourceEmail as the unique ID of the respective resource calendar.

Here's the thing I did to make unavailable resources to be available (bookable):

{
    "scope": {
        "type": "domain",
        "value": "orangery.io"  # if you selected type as `domain` you should write your domain name here.
    },
    "role": "writer"
}

[NOTE]:

With this procedure, you will need to the https://www.googleapis.com/auth/calendar authorization scope as well.