Unexpected keyword argument

In my application, the API ENDPOINT notify_burned is notified when a voucher_id is used (“burned”).

The calling request is:
https://my-app-url/_/api/notify_burned/39b99819-5cec-444c-b510-a8ef5291804f?customer_name=NAME&customer_lastname=LASTNAME&customer_product=PROD%3AFirma%20Remota%2FDEV%3A7%2FBLINDENV%3A0%2FOTP%3A3

I get the error:

TypeError: notify_burned() got an unexpected keyword argument 'customer_name'
at /downlink/anvil/_server.py, line 1340

I can’t understand why, since customer_name is passed in the querystring and my endpoint declaration is this:

@anvil.server.http_endpoint("/notify_burned/:voucher_id")
def notify_burned(voucher_id):
  print("-NOTIFY-BURNED-----------------------------")
  r = anvil.server.request
  qp = r.query_params if r.query_params is not None else {}
  fp = r.form_params if r.form_params is not None else {}
  bj = r.body_json if r.body_json is not None else {}
  origin = r.origin
  params = {**querystring, **qp, **fp, **bj}
  print(f"Params: {params}")
  customer_name = params['customer_name'] if 'customer_name' in params else None
  customer_lastname = params['customer_lastname'] if 'customer_lastname' in params else None
  customer_product = params['customer_product'] if 'customer_product' in params else None

In the session log, I don’t even see the “-NOTIFY-BURNED-------------” print, so I guess I never get into the function and get stuck at the definition.
But I can’t see how the function gets the keyword argument ‘customer_name’

Where am I doing wrong?

Thanks

It looks like Anvil receives the parameter customer_name and doesn’t know what to do with it.

Perhaps the word customer_name is somewhere in the URL?

Or in the body?

Try to add the argument and see what happens: def notify_burned(voucher_id, customer_name)

It’s my understanding that query parameters are passed to the endpoint as keyword arguments. That’s exactly what the message is telling you, you aren’t catching those keyword arguments.

The catch all way to do it is to add **kwargs to your parameter list, and then index into that to get individual parameters.

2 Likes

Oh my!
I forgot to add **params to the declaration of notify_burned(voucher_id):
I’ve re-read that declaration 1 thousand times.
That’s what happens when you code late night.
Thanks @jshaffstall

3 Likes