Update DB using endpoint

I am trying to update the db using custom endpoint, i have this code

    def initialize(self):
        self.add_endpoint(
            "{project_name}/update_playlist_data",
            self.set_sg_playlist_data,
            method="POST",
        )
    async def set_sg_playlist_data(
            self,
            project_name: ProjectName,
            code,
            tags,
            data
    ) -> Response:
        result = {'project_name': project_name, 'code': code, 'tags': tags, 'data': data}
        await check_sg_playlist_data_table(project_name)

        async with Postgres.acquire() as conn:
            async with conn.transaction():
                query = (
                    f"""
                    INSERT INTO project_{project_name}.sg_playlist_data (code, tags, data)
                    VALUES ({code}, {tags}, {data})
                    """
                )

                await conn.execute(query)

                return Response(status_code=200)

but how do i insert the data?

endpoint = "addons/dailies_submitter/0.0.3/SKT_DEMO/update_playlist_data"
data = {"project_name": "SKT_DEMO", "code": "Director Review 12.01.2015", "tag": {}, "data": {}}
response = ayon_api.post(endpoint, **data)

running this keeps giving me a 400 error,
am i updating the db correctly?

I wonder if your are missing a / at the beginning.
Also, I wonder if you should use the post method like this

endpoint = "/addons/dailies_submitter/0.0.3/SKT_DEMO/update_playlist_data"
response = ayon_api.post(
    endpoint, 
    project_name="SKT_DEMO", 
    code="Director Review 12.01.2015",
    tag={},
    data={}
)

Hi mustafa, i tried the changes you suggested, but unfortunately i am still getting the same error,
{‘code’: 400, ‘detail’: ‘Validation error’}

You might be best off checking the server logs to get more details on the validation error?

this is what i get in the server

[{'loc': ('query', 'code'), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('query', 'tags'), 'msg': 'field required', 'type': 'value_error.missing'}, {'loc': ('query', 'data'), 'msg': 'field required', 'type': 'value_error.missing'}]

It’s saying it’s missing the required fields code, tags and data

ayon_api.post should be passing the kwargs as the json argument to the post request. Whether that’s correct here I have no idea (I’m not knowledgeable about web requests at all). I wonder if trying ayon_api.raw_post instead may help here.

@martin.wacker might know better what the exact request should be here.

So it seems i had misspelled the tags key now that i have fixed it i still keep getting
[{‘loc’: (‘query’, ‘code’), ‘msg’: ‘field required’, ‘type’: ‘value_error.missing’}]
but i ame passing that value to it.

async def check_sg_playlist_data_table(project_name: str) -> None:
    """Checks for existence of `sg_playlist_data` table, creates if not."""
    logging.info(f'check_sg_playlist_data_table: {project_name}')
    await Postgres.execute(
        f"CREATE TABLE IF NOT EXISTS project_{project_name}.sg_playlist_data (code VARCHAR NOT NULL,tags JSONB NOT NULL,data JSONB NOT NULL);"
    )

So this is the db creating i have, it seems its not picking up the correct data type, if i change it to JSONB and pass a dict it seems to work, any idea as how to pass a string?