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

Adding a list_forms method. (Code provided below) #11

Open
cschulze86 opened this issue Nov 21, 2023 · 2 comments
Open

Adding a list_forms method. (Code provided below) #11

cschulze86 opened this issue Nov 21, 2023 · 2 comments

Comments

@cschulze86
Copy link

cschulze86 commented Nov 21, 2023

Im interested to list all form_id/dataset_ids the logged-in user has access to, if thats possible.

** Solved below **

@cschulze86 cschulze86 changed the title Any way to list all projects (similar to the pyodk.projest.list()) method? Any way to list all projects (similar to the pyodk.projects.list()) method? Nov 21, 2023
@cschulze86
Copy link
Author

cschulze86 commented Nov 21, 2023

Hello.

I created the below method for your class that does exactly whats needed. I checked, and it looks like the form versions displayed are all the most recently deployed ones, as there are no duplicates in the list returned in the response. Would be grateful if you could confirm that, though - seems you've been poking around the API a bit more than I have.

Any chance you can stick this in an update so I don't need to build/maintain parallel modules to get/keep this running?

Thanks in advance!

    def list_forms(self):
        """
        Fetches a list of dictionaries, with all live forms on server. Includes only the most recent versions.
        :return: list of dictionaries, with each dictionary containing information for each form on server
        """
        headers = self.__auth()
        url = f"https://{self.server_name}.surveycto.com/console/forms-groups-datasets/get"

        try:
            response = self._sesh.get(
                url,
                cookies=self._sesh.cookies,
                headers=headers,
            )
            response.raise_for_status()
        except requests.exceptions.HTTPError as e:
            response = False
            raise e
        
        return response.json().get('forms')

@cschulze86 cschulze86 changed the title Any way to list all projects (similar to the pyodk.projects.list()) method? Adding a list_forms method. (Code provided beloe) Nov 21, 2023
@cschulze86 cschulze86 changed the title Adding a list_forms method. (Code provided beloe) Adding a list_forms method. (Code provided below) Nov 21, 2023
@edodge
Copy link
Member

edodge commented Nov 22, 2023

Hi @cschulze86 thanks for raising this. Do you think you could create a pull request with the new method (and update the README)? Then we can test and merge it in. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants