Skip to content

Cannot POST to /api/visits #231

@peterfk

Description

@peterfk

This issue is very similar to #139 in that the POST payload is just

{ "date": "2013-01-01", "description": "rabies shot" }

It's missing the foreign key to Pets table so you get this error

{ "type": "http://localhost:9966/petclinic/api/visits", "title": "DataIntegrityViolationException", "status": 404, "detail": "could not execute statement [NULL not allowed for column \"PET_ID\"; SQL statement:\ninsert into visits (visit_date,description,pet_id,id) values (?,?,?,default) [23502-232]] [insert into visits (visit_date,description,pet_id,id) values (?,?,?,default)]; SQL [insert into visits (visit_date,description,pet_id,id) values (?,?,?,default)]; constraint [null]", "instance": "/petclinic/api/visits", "timestamp": "2025-05-22T20:34:23.793194Z" }

There is also a separate POST method

/api/owners/{ownerId}/pets/{petId}/visits

which requires the petId in the URL and does work so presumably that's what everyone is using. Not sure why it's part of api/owners though? And I don't think you would really need to pass the ownerId to insert into the visit table.

Not sure what the best approach is but it may be possible to list petId as an optional field in the /api/visit method, similar to the date field.

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