nylas / nylas-python

Python bindings for the Nylas Platform API
MIT License
101 stars 77 forks source link

Python SDK (Nylas API v3) Error Messages #347

Closed relaxedtomato closed 8 months ago

relaxedtomato commented 9 months ago

Describe the bug Testing the Python SDK and receiving error messages for various calls, will include source code and errors below.

POST /v3/grants/{grant_id}/calendars/free-busy

code sample:

# SDK doesn't accept identifer
# https://nylas-python-sdk-reference.pages.dev/reference/resources/calendars/#resources.calendars.Calendars.get_availability

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")
email = os.environ.get("EMAIL")

free_busy = nylas.calendars.get_free_busy(
  grant_id,
  request_body={
    "start_time": 1630435200,
    "end_time": 1630521600,
    "emails": [email]
  }
)

print(free_busy)

error message


# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/get-free-busy.py", line 19, in <module>
#     free_busy = nylas.calendars.get_free_busy(
#                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/calendars.py", line 155, in get_free_busy
#     return Response.from_dict(json_response, GetFreeBusyResponse)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/models/response.py", line 46, in from_dict
#     data=generic_type.from_dict(resp["data"]),
#          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/api.py", line 70, in from_dict
#     return _decode_dataclass(cls, kvs, infer_missing)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 150, in _decode_dataclass
#     kvs = {decode_names.get(k, k): v for k, v in kvs.items()}
#                                                  ^^^^^^^^^
# AttributeError: 'list' object has no attribute 'items'

GET /v3/grants/{grant_id}/messages/schedules

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")

messages = nylas.messages.list_scheduled_messages(
  grant_id
)

print(messages)

error message

# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/get-message-schedules.py", line 15, in <module>
#     messages = nylas.messages.list_scheduled_messages(
#                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/messages.py", line 159, in list_scheduled_messages
#     return Response.from_dict(json_response, ScheduledMessagesList)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/models/response.py", line 46, in from_dict
#     data=generic_type.from_dict(resp["data"]),
#          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/api.py", line 70, in from_dict
#     return _decode_dataclass(cls, kvs, infer_missing)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 150, in _decode_dataclass
#     kvs = {decode_names.get(k, k): v for k, v in kvs.items()}
#                                                  ^^^^^^^^^
# AttributeError: 'list' object has no attribute 'items'

GET /v3/grants/{grant_id}/messages/schedules/

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")
schedule_id = os.environ.get("SCHEDULE_ID")

event = nylas.messages.find_scheduled_message(
  grant_id,
  schedule_id,
)

print(event)

error message

# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/get-message-scheduled-by-id.py", line 16, in <module>
#     event = nylas.messages.find_scheduled_message(
#             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/messages.py", line 179, in find_scheduled_message
#     return Response.from_dict(json_response, ScheduledMessage)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/models/response.py", line 46, in from_dict
#     data=generic_type.from_dict(resp["data"]),
#          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/api.py", line 70, in from_dict
#     return _decode_dataclass(cls, kvs, infer_missing)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 224, in _decode_dataclass
#     init_kwargs[field.name] = _support_extended_types(field_type,
#                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 251, in _support_extended_types
#     else field_type(field_value))
#          ^^^^^^^^^^^^^^^^^^^^^^^
# ValueError: invalid literal for int() with base 10: '846cab57-cfa6-493e-9fb3-a448b12b9406'

POST /v3/grants/{grant_id}/messages/smart-compose

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")
email = os.environ.get("EMAIL")

message = nylas.messages.smart_compose.compose_message(
  grant_id,
  request_body={
    "prompt": "Tell my colleague how we can use Nylas APIs",
  }
)

print(message)

error message

# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/smart-compose.py", line 16, in <module>
#     message = nylas.messages.smart_compose.compose_message(
#               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/smart_compose.py", line 25, in compose_message
#     return self._http_client.execute(
#            ^^^^^^^^^^^^^^^^^^^^^^^^^
# AttributeError: 'HttpClient' object has no attribute 'execute'. Did you mean: '_execute'?

POST /v3/grants/{grant_id}/messages/{message_id}/smart-compose

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")
message_id = os.environ.get("MESSAGE_ID")

message = nylas.messages.smart_compose.compose_message_reply(
  grant_id,
  message_id,
  request_body={
    "prompt": "Respond to the email",
  }
)

print(message)

error message

# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/smart-compose-response.py", line 16, in <module>
#     message = nylas.messages.smart_compose.compose_message_reply(
#               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/smart_compose.py", line 46, in compose_message_reply
#     return self._http_client.execute(
#            ^^^^^^^^^^^^^^^^^^^^^^^^^
# AttributeError: 'HttpClient' object has no attribute 'execute'. Did you mean: '_execute'?

GET /v3/grants/{grant_id}/drafts

GET /v3/grants/{grant_id}/drafts/

PUT /v3/grants/{grant_id}/drafts/

DELETE /v3/grants/{grant_id}/drafts/

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")

drafts = nylas.drafts.list(
  grant_id,
)

print(drafts)

error message

# python3 retrieve-all-drafts.py
# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/retrieve-all-drafts.py", line 15, in <module>
#     drafts = nylas.drafts.list(
#              ^^^^^^^^^^^^
# AttributeError: 'Client' object has no attribute 'drafts'. Did you mean: 'grants'?

GET /v3/grants/{grant_id}/contacts

code

from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
    os.environ.get('NYLAS_API_KEY'),
    os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("GRANT_ID")

contacts = nylas.contacts.list(
  grant_id,
)

print(contacts)

error message


# Traceback (most recent call last):
#   File "/Users/ram/Documents/v3-code-samples-node/src/retrieve-all-contacts.py", line 15, in <module>
#     contacts = nylas.contacts.list(
#                ^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/resources/contacts.py", line 41, in list
#     return super(Contacts, self).list(
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/handler/api_resources.py", line 15, in list
#     return ListResponse.from_dict(response_json, response_type)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/nylas/models/response.py", line 93, in from_dict
#     converted_data.append(generic_type.from_dict(item))
#                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/api.py", line 70, in from_dict
#     return _decode_dataclass(cls, kvs, infer_missing)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 220, in _decode_dataclass
#     init_kwargs[field.name] = _decode_generic(field_type,
#                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 311, in _decode_generic
#     res = _decode_generic(type_arg, value, infer_missing)
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 291, in _decode_generic
#     xs = _decode_items(_get_type_arg_param(type_, 0), value, infer_missing)
#          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 399, in _decode_items
#     return list(_decode_item(type_args, x) for x in xs)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 399, in <genexpr>
#     return list(_decode_item(type_args, x) for x in xs)
#                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 372, in _decode_item
#     return _decode_dataclass(type_arg, x, infer_missing)
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 220, in _decode_dataclass
#     init_kwargs[field.name] = _decode_generic(field_type,
#                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 311, in _decode_generic
#     res = _decode_generic(type_arg, value, infer_missing)
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Users/ram/Documents/v3-code-samples-node/src/env/lib/python3.12/site-packages/dataclasses_json/core.py", line 272, in _decode_generic
#     res = type_(value)
#           ^^^^^^^^^^^^
#   File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/enum.py", line 744, in __call__
#     return cls.__new__(cls, value)
#            ^^^^^^^^^^^^^^^^^^^^^^^
#   File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/enum.py", line 1158, in __new__
#     raise ve_exc
# ValueError: 'personal' is not a valid ContactType
mrashed-dev commented 8 months ago

Hey @relaxedtomato! The PR should close this issue. It fixes the free busy and scheduled messages errors. The errors appearing for drafts, smart compose and contacts were fixed for v6 you might be on a beta version.