tripletex-api2 icon indicating copy to clipboard operation
tripletex-api2 copied to clipboard

[Request] Python SDK?

Open hakontro opened this issue 3 years ago • 7 comments

Hi.

Great API, congrats.

I've found the Python examples, just wondering if you guys happen to have a Python SDK that you can open source, or if you know if an open source one exists?

hakontro avatar Dec 08 '22 13:12 hakontro

The closes to an official Python SDK that exists would be the Python client Swagger-codegen could generate for you. Beyond that you would have to make it yourself or use some other code generator that supports Swagger specs.

tlxtellef avatar Dec 09 '22 08:12 tlxtellef

Found out about the auto-generation from the swagger docs: cool.

Any success in using that with Python? Seems to not be able to correctly get tokens (it fails on decoding the token to some sort of model).. Token is fetched correctly though, maybe just a swagger-codegen issue

Exception has occurred: ValueError
Invalid value for `token`, must not be `None`
  File "/code/tripletex-sdk/tripletex/models/employee_token.py", line 236, in token
    raise ValueError(
  File "/code/tripletex-sdk/tripletex/models/employee_token.py", line 87, in __init__
    self.token = token
  File "/code/tripletex-sdk/tripletex/api_client.py", line 695, in __deserialize_model
    instance = klass(**kwargs)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 286, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 693, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 286, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 693, in __deserialize_model
    kwargs[attr] = self.__deserialize(value, attr_type)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 286, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 247, in deserialize
    return self.__deserialize(data, response_type)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 174, in __call_api
    return_data = self.deserialize(response_data, response_type)
  File "/code/tripletex-sdk/tripletex/api_client.py", line 343, in call_api
    return self.__call_api(
  File "/code/tripletex-sdk/tripletex/api/tokensession_api.py", line 150, in token_session_create_create_with_http_info
    return self.api_client.call_api(
  File "/code/tripletex-sdk/tripletex/api/tokensession_api.py", line 59, in token_session_create_create
    (data) = self.token_session_create_create_with_http_info(
  File "/code/tripletex-sdk/test/test_invoice.py", line 43, in testInvoice
    st = tripletex.TokensessionApi().token_session_create_create(
ValueError: Invalid value for `token`, must not be `None`

hakontro avatar Dec 09 '22 12:12 hakontro

Probably a bug in the code generator then, but I will have a look to see if there could be a specification issue. I do doubt it is a specification issue tho as we do use Swagger to generate our own clients for running integration tests with.

Do note that the specification version Tripletex is using is OpenAPI Specification V2 and not V3.

tlxtellef avatar Dec 09 '22 12:12 tlxtellef

Yeah, have the same feeling. Thanks for having a look, if you want to reproduce: one way to make it fail is to try getting a token

tripletex.TokensessionApi().token_session_create_create(
            consumer_token=<c_token>, employee_token=<e_token>, expiration_date="2022-12-10"
        )

hakontro avatar Dec 09 '22 12:12 hakontro

Hi again!

I think maybe the docs are off. For example, the EmployTooken.token field is marked as required, as is Department.name, but neither are returned from the API (at least not always?).

Could we be misunderstanding something here, or are docs wrong/API has bugs?

image

image

hakontro avatar Dec 13 '22 14:12 hakontro

Required is only for when you submit said models, it might look a bit weird in some cases and that is due to us using the same model for both incoming and outgoing data.

What fields are returned are controlled by the fields parameter. The default of fields in most cases is to include all fields on the first level (*).

In the case you show here consumerToken, & employeeToken are top level fields so they are included but the fields in the model on said fields are not, that is why there is only 2 fields being populated on them (id & url). To get the values of employeeToken in this case then fields could for example be set to *,employeeToken(*)

tlxtellef avatar Dec 14 '22 08:12 tlxtellef

Gotcha, that makes sense.

Required is only for when you submit said models

Just trying to understand here: lastName and firstName are the only required fields on Employee according to the docs, but trying to POST /employee we get an error (brukerType kan ikke være null). In other words, userType is also required, right?

https://api.tripletex.io/v2-docs/#/employee/Employee_post

hakontro avatar Dec 14 '22 09:12 hakontro