Skip to content

get_current_user() /v4/me endpoint issue with SDK #20

@marklynch

Description

@marklynch

I've been getting my head around the API via the SDK and found the following issue when calling the get_current_user() method. I'm getting the following validation error:

{
detail: "Error calling OpenElectricity /v4/me endpoint: 2 validation errors for OpennemUserResponse
version
  Field required [type=missing, input_value={'data': {'id': 'key_53tF...a': {'remaining': 497}}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing
created_at
  Field required [type=missing, input_value={'data': {'id': 'key_53tF...a': {'remaining': 497}}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/missing"
}

This appears to be because the /v4/me endpoint doesn't return the version or created_at fields - but the validation has a hard requirement on this.

Solution to this could be to make those fields optional in the SDK - or add the fields to the API response.

Option 1: make fields optional
https://github.com/opennem/openelectricity-python/blob/4fabba7a7a0c93f762585a5b2027eab054a5a798/openelectricity/models/base.py#L13C1-L21C37

Option 2: update the API to return version and created_at

I've tried to have a little dig in to this code - but it's not obvious to me why it's not already returning this value based on:

However I did check via a curl request

curl -X GET "https://api.openelectricity.org.au/v4/me" -H "Authorization: Bearer your_api_key_here"

and it's returns the following format which confirms it's not adding the version and created_at fields:

{
  "data": 
  {
    "id":"key_XXXXX",
    "full_name":"XXXX",
    "email":"XXXX",
    "owner_id":"XXXX",
    "plan":"BASIC",
    "meta":{"remaining":496}
  }
}

Hope this helps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions