HealthITAU / pyconnectwise

A library for simplifying interactions with the ConnectWise Manage API in Python
https://healthit.com.au
GNU General Public License v3.0
42 stars 7 forks source link

CompanyConfiguration - Input should be a valid dictionary #28

Open J-Gal02 opened 2 weeks ago

J-Gal02 commented 2 weeks ago

I've run into an issue when trying to get the details from api.company.configurations.id(id).get() where Pydantic will throw the following error:

[1] [2024-06-17 12:17:58,237] ERROR in app: Exception on /api/v1/tickets/<ID>/configurations [GET]
[1] Traceback (most recent call last):
[1]   File "/home/hit/.local/lib/python3.10/site-packages/flask/app.py", line 1455, in wsgi_app
[1]     response = self.full_dispatch_request()
[1]   File "/home/hit/.local/lib/python3.10/site-packages/flask/app.py", line 869, in full_dispatch_request
[1]     rv = self.handle_user_exception(e)
[1]   File "/home/hit/.local/lib/python3.10/site-packages/flask/app.py", line 867, in full_dispatch_request
[1]     rv = self.dispatch_request()
[1]   File "/home/hit/.local/lib/python3.10/site-packages/flask/app.py", line 852, in dispatch_request
[1]     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
[1]   File "<Filepath>/api/index.py", line 641, in API_GetTicketConfigurations
[1]     config['id']).get()
[1]   File "/home/hit/.local/lib/python3.10/site-packages/pyconnectwise/endpoints/manage/CompanyConfigurationsIdEndpoint.py", line 84, in get
[1]     return self._parse_one(
[1]   File "/home/hit/.local/lib/python3.10/site-packages/pyconnectwise/endpoints/base/connectwise_endpoint.py", line 167, in _parse_one
[1]     return model_type.model_validate(data)
[1]   File "/home/hit/.local/lib/python3.10/site-packages/pydantic/main.py", line 551, in model_validate
[1]     return cls.__pydantic_validator__.validate_python(
[1] pydantic_core._pydantic_core.ValidationError: 34 validation errors for CompanyConfiguration
[1] questions.0.answer
[1]   Input should be a valid dictionary [type=dict_type, input_value='E', input_type=str]
[1]     For further information visit https://errors.pydantic.dev/2.7/v/dict_type
[1] questions.2.answer
[1]   Input should be a valid dictionary [type=dict_type, input_value='macOS', input_type=str]
[1]     For further information visit https://errors.pydantic.dev/2.7/v/dict_type

I have included the following demo code to replicate this issue:

@app.route('/api/v1/tickets/<int:ticketNo>/configurations', methods=['GET'])
def API_GetTicketConfigurations(ticketNo):
    if request.method == "GET":
        configs_rawdata = api.service.tickets.id(ticketNo).configurations.get()
        f = open("configsdump.txt", "w")
        f.write(str(configs_rawdata))
        f.close()

        configs_formatted = []
        for config in configs_rawdata:
            config_format = {
                "id": get_attribute(config, 'id'),
                "name": get_attribute(config, 'name'),
                "info": get_attribute(config, '_info'),
            }
            configs_formatted.append(config_format)
        for config in configs_formatted:
            moreconfig_rawdata = api.company.configurations.id(
                config['id']).get()
            f2 = open("moreconfigsdump.txt", "a")
            f2.write(str(moreconfig_rawdata))
            f2.close()

        return (jsonify("Check config dump"))

The ConnectWise API suggests that the answer of a QuestionReference should return a dict, where we would expect to receive strings