Skip to content

Conversation

@connorads
Copy link

@connorads connorads commented Oct 17, 2024

⚠️ I know you're not supposed to edit this file manually, this is just to illustrate a fix and where the issue is

The basic issue is that I haven't been able to run get push operation.

I could be using the SDK wrong, if so just let me know.

# requirements.txt
codat-lending==7.1.0
codat-platform==3.5.0

Say if I try to create a supplier and then run get push operation I get the following error
ValueError: invalid literal for int() with base 10: '__SPEAKEASY_UNSET__'

# script.py
import os
import base64
import codat_lending
import codat_lending.codatlending_accounting_bank_data
from codat_lending.models import shared, operations
import codatplatform

codat_api_key = os.getenv("CODAT_API_KEY")

if codat_api_key is None:
    raise ValueError("CODAT_API_KEY environment variable is not set")

encoded_api_key = base64.b64encode(codat_api_key.encode()).decode()

lending_client = codat_lending.CodatLending(
    security=shared.Security(
        auth_header=f"Basic {encoded_api_key}",
    ),
)


COMPANY_ID = "" # TODO: Replace with your company ID
CONNECTION_ID = "" # TODO: Replace with your connection ID


request = operations.GetAccountingProfileRequest(
    company_id=COMPANY_ID,
)
response = lending_client.company_info.get_accounting_profile(request=request)

if response is None:
    raise ValueError("response is None")

supplier_create_request = operations.CreateSupplierRequest(
    accounting_supplier=shared.AccountingSupplier(
        addresses=[
            shared.AccountingAddress(
                line1="456 Oakwood Avenue",
                city="Manchester",
                country="UK",
                postal_code="M12 4LT",
                type=shared.AccountingAddressType.BILLING,
            ),
        ],
        default_currency="GBP",
        email_address="info@randomcompany.co.uk",
        registration_number="12345678",
        status=shared.SupplierStatus.ACTIVE,
        supplier_name="RANDOM COMPANY LTD",
    ),
    company_id=COMPANY_ID,
    connection_id=CONNECTION_ID,
)

supplier_create_response = lending_client.loan_writeback.suppliers.create(
    request=supplier_create_request
)

if supplier_create_response is None:
    raise ValueError("supplier_create_response is None")


platform_client = codatplatform.CodatPlatform(
    security=codatplatform.settings.shared.Security(
        auth_header=f"Basic {encoded_api_key}",
    ),
)

push_operation_request = (
    codatplatform.push_data.operations.get_push_operation.GetPushOperationRequest(
        company_id=COMPANY_ID,
        push_operation_key=supplier_create_response.push_operation_key,
    )
)

push_operation_response = platform_client.push_data.get_operation(
    request=push_operation_request
)

I've tried looking into the code and I've noticed that it doesn't work if I use the PushOperation from codat_lending.

# issue.py

import codat_lending
import codatplatform

# Note: The UUIDs have been randomised
http_res_text = '{"changes":[{"type":"Created","recordRef":{"id":"3f9e8a7c-12b4-4a67-b918-67389f2f3b75","dataType":"suppliers"}}],"dataType":"suppliers","companyId":"1bfc7e02-d5aa-4032-94b9-01f2a15bb635","pushOperationKey":"4e50899f-41f2-4f9b-bc57-5dbd26c2f633","dataConnectionKey":"d25b7c4e-8214-4e12-a306-e5f5d2c6f1c9","requestedOnUtc":"2024-10-17T15:44:38.9481460Z","completedOnUtc":"2024-10-17T15:44:39.0652450Z","status":"Success","statusCode":200}'

codat_lending_out = codat_lending.utils.unmarshal_json(http_res_text, codat_lending.Optional[codat_lending.shared.PushOperation])
# codat_lending.shared.PushOperation works fine ✅ 
print(codat_lending_out)

codatplatform_out = codatplatform.utils.unmarshal_json(http_res_text, codatplatform.Optional[codatplatform.shared.PushOperation])
# codatplatform.shared.PushOperation raises ValueError: invalid literal for int() with base 10: '__SPEAKEASY_UNSET__' ❌
print(codatplatform_out)

Link to the working model is https://github.com/codatio/client-sdk-python/blob/main/lending/src/codat_lending/models/shared/pushoperation.py

@connorads connorads marked this pull request as ready for review October 17, 2024 16:27
@connorads connorads requested a review from dcoplowe as a code owner October 17, 2024 16:27
@dcoplowe
Copy link
Contributor

dcoplowe commented Oct 18, 2024

Hi @connorads,

Thank you for getting in touch.

The issue arises because our SDKs are distinct and do not share a common library for models like PushOperation. This is due in part to how our SDKs are generated from OpenAPI Specifications. To address this, we’ve designed each SDK to be self-contained, meaning the lending SDK includes all the necessary methods for lenders.

Therefore, the lending client should provide everything you need to implement loan writeback. To access the push operation, use the following method: sdk.loan_writeback.create_operations.get within the lending client.

@connorads
Copy link
Author

Thanks @dcoplowe, that makes sense. Seems to be working now.

I didn't even know about the lending Python SDK docs 🫠
Do these README.mds get built and put on https://docs.codat.io/, and/or are they referenced anywhere else?

@connorads
Copy link
Author

Raised the issue codatio/codat-docs#1401

@connorads connorads closed this Oct 21, 2024
@connorads connorads deleted the patch-1 branch October 23, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants