Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong format of urlencoded list #5

Open
lotooo opened this issue Sep 26, 2022 · 5 comments
Open

Wrong format of urlencoded list #5

lotooo opened this issue Sep 26, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@lotooo
Copy link

lotooo commented Sep 26, 2022

Describe the bug

When using this library trying to update an existing check, I receive a 400 because some fields use the wrong format.

The 2 specific fields I tested that a reporting bad format are tags and 'contact_groups.

To Reproduce
Steps to reproduce the behavior:

  1. Call update_uptime_test with a list as tags or contact_groups
  2. You receive a 400

Expected behavior

It works and respect the docs in https://www.statuscake.com/api/v1/#tag/uptime/operation/update-uptime-test

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

I enabled urllib debug level and it seems the generated URL is using contact_groups=111111&contact_groups=111112 instead of contact_groups[]=111111&contact_groups[]=111112, not sure it's a SDK/library problem, I did a workaround using requests and I had to rename the attributes to make them work.

@lotooo lotooo added the bug Something isn't working label Sep 26, 2022
@tomasbasham
Copy link
Member

tomasbasham commented Sep 26, 2022

Thank you for the report. This is helpful for improving the package. Since this package is in the alpha phase we'd advise that it not be used in production scenarios as there are still issues, as you've demonstrated. At present we have no clear timeline as to when this issue will be fixed. Hopefully in the near future

@kkerce
Copy link

kkerce commented Oct 1, 2022

+1

Especially since https://www.statuscake.com/api/ indicates the existing API will be deprecated today:
statuscake_api_deprecation

@kkerce
Copy link

kkerce commented Dec 13, 2022

@tomasbasham Can this issue be addressed soon? It's a major blocker if uptime tests with contact groups can't be created via this SDK.

@joachimtingvold
Copy link

joachimtingvold commented Aug 7, 2023

Since the API doesn't support JSON payload either (which would be way easier via r.post(url,json=data,headers=headers)), you have to use the old method with "list of tuples" as input data to requests. Quick excerpt shown below (if you have all the required API parameters in a dict);

def dict_to_tuple_list(d):
  tuple_list = []
  for key in d:
    if type(d[key]) is list:
      for item in d[key]:
        tuple_list.append( (key + '[]', item) )
    else:
      tuple_list.append( (key, d[key]) )
  return tuple_list

headers = {
  "Authorization": f"Bearer { api_key }"
}
tuple_data = dict_to_tuple_list(some_dict)
requests.post(f"{api_url}/{endpoint}", data=tuple_data, headers=headers)

@bobbythebus
Copy link

@tomasbasham any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

5 participants