From f3dd1227573d4a60495f5e1281d5039dd2e06e10 Mon Sep 17 00:00:00 2001
From: Niraj Adhikari <nrjadkry@gmail.com>
Date: Thu, 28 Dec 2023 11:46:20 +0545
Subject: [PATCH] created an api which returns the form fields for the xform in
 odk central

---
 osm_fieldwork/OdkCentral.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/osm_fieldwork/OdkCentral.py b/osm_fieldwork/OdkCentral.py
index 3759664f9..ffaa4aadf 100755
--- a/osm_fieldwork/OdkCentral.py
+++ b/osm_fieldwork/OdkCentral.py
@@ -1002,6 +1002,33 @@ def publishForm(self,
             log.info(f"Published {xform} on Central.")
         return result.status_code
 
+
+    def form_fields(self,
+                    projectId:int,
+                    xform:str):
+
+        """
+        Retrieves the form fields for a xform from odk central.
+
+        Args:
+            projectId (int): The ID of the project on ODK Central
+            xform (str): The XForm to get the details of from ODK Central
+
+        Returns:
+            dict: A json object containing the form fields.
+
+        """
+
+        if xform.find("_") > 0:
+            xid = xform.split('_')[2]
+        else:
+            xid = xform
+
+        url = f"{self.base}projects/{projectId}/forms/{xid}/fields?odata=true"
+        result=self.session.get(url, auth=self.auth)
+        return result.json()
+
+
     def dump(self):
         """Dump internal data structures, for debugging purposes only"""
         # super().dump()