@@ -163,6 +163,19 @@ def add_extra_url_params(self, url, params):
163163
164164 return url
165165
166+ def get_survey_data_layouts (self , survey_id ):
167+ self .check_auth_headers ()
168+ data_layouts_url = '{}/surveys/{}/data-layouts' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
169+ data_layouts_response = requests .get (data_layouts_url , headers = self ._authentication_headers )
170+ if data_layouts_response .status_code != 200 :
171+ raise CmixError (
172+ 'CMIX returned a non-200 response code while getting data_layouts: {} and error {}' .format (
173+ data_layouts_response .status_code ,
174+ data_layouts_response .text
175+ )
176+ )
177+ return data_layouts_response .json ()
178+
166179 def get_survey_definition (self , survey_id ):
167180 self .check_auth_headers ()
168181 definition_url = '{}/surveys/{}/definition' .format (CMIX_SERVICES ['survey' ][self .url_type ], survey_id )
@@ -242,25 +255,14 @@ def create_export_archive(self, survey_id, export_type):
242255 )
243256 archive_json = archive_response .json ()
244257
245- layout_url = '{}/surveys/{}/data-layouts/' .format (CMIX_SERVICES ['survey' ]["BASE_URL" ], survey_id )
246- layout_response = requests .get (layout_url , headers = self ._authentication_headers )
247- if layout_response .status_code != 200 :
248- raise CmixError (
249- 'CMIX returned a non-200 response code: {} and error {}' .format (
250- layout_response .status_code ,
251- layout_response .text
252- )
253- )
258+ layout_json = self .get_survey_data_layouts (survey_id )
254259 layout_id = None
255- for layout in layout_response . json () :
260+ for layout in layout_json :
256261 if layout .get ('name' ) == 'Default' :
257262 layout_id = layout .get ('id' )
258263 if layout_id is None :
259264 raise CmixError (
260- 'Layouts response did not contain a "Default" layout. Response Code: {}, Body {}' .format (
261- layout_response .status_code ,
262- layout_response .content
263- )
265+ 'Layouts response did not contain a "Default" layout.'
264266 )
265267
266268 archive_json ['dataLayoutId' ] = layout_id
0 commit comments