-2

f-string or a URL is not working as well as params is not constructing the URL and the results are not as expected

I am trying to pass two variables in query parameters.

  • Option 1:

    f"https://apiproduct-hotfix.resilix.ai/api/v1/accounts/5d729b3f4556301143be5b58/engagement/cadence_executions?query={'entity_id': {patient_id},'cadence_id':{cloned_cadence_id}}"
    

    is throwing ValueError: Invalid format specifier

  • Option 2:

    params = {'entity_id': {patient_id}, 'cadence_id': {cloned_cadence_id}}
    cadence_execution_url = (f"https://apiproduct-hotfix.resilix.ai/api/v1/accounts/5d729b3f4556301143be5b58"
                                 f"/engagement/cadence_executions")
    cadences_execution = requests.get(cadence_execution_url, headers=auth, timeout=3000,params=params)    
    

    is returning the cadences_execution.url as

    https://apiproduct-hotfix.resilix.ai/api/v1/accounts/5d729b3f4556301143be5b58/engagement/cadence_executions?entity_id=64ea20f4038ca537b25577b3&cadence_id=64ea20f3c8f868262bb5a15c
    

    and the query is not applied at all

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Your first one actually gives me a different error: `NameError: name 'patient_id' is not defined`. Looks like your [MRE] is neither minimal nor reproducible. – Kelly Bundy Aug 26 '23 at 16:10
  • 1
    Option 1 is simply not how query parameters work in URLs. `params = {'entity_id': {patient_id}, 'cadence_id': {cloned_cadence_id}}` defines a dictionary whose values are _sets_. – jonrsharpe Aug 26 '23 at 16:10
  • Inside an f-string, python expects `{}` characters to surround simple variable names, i.e. `{a} {b} {c}`. But your f-string has `{}` characters surrounding a dictionary, which requires special formatting inside an f-string. – John Gordon Aug 26 '23 at 17:10

0 Answers0