I wrote this issue report on the community forums, (post):
I am having trouble getting a data source published through the REST API.
The resulting error is 400011: Bad Request.
If I check the request against the 3.0 REST API XSD, it is valid:
According to XML Spy at least.
I changed the request_factory.py to do this:
class DatasourceRequest(object):
def _generate_xml(self, datasource_item, connection_credentials=None, connections=None):
xml_request = ET.Element('tsRequest')
datasource_element = ET.SubElement(xml_request, 'datasource')
datasource_element.attrib['name'] = datasource_item.name
if connection_credentials is not None and connections is not None:
raise RuntimeError('You cannot set both connections and connection_credentials')
if connection_credentials:
credentials_element = ET.SubElement(datasource_element, 'connectionCredentials')
credentials_element.attrib['name'] = connection_credentials.name
credentials_element.attrib['password'] = connection_credentials.password
credentials_element.attrib['embed'] = 'true' if connection_credentials.embed else 'false'
if connection_credentials.oauth:
credentials_element.attrib['oAuth'] = 'true'
project_element = ET.SubElement(datasource_element, 'project')
project_element.attrib['id'] = datasource_item.project_id
The fix is to have the project definition come after the credentials. Before this change, the request was not valid according to the XSD.
Overall, I am trying to achieve this:
- change database environment in the data source
- publish the data source with changed credentials
- I am using the document and service Python SDK's to do this
Script is attached.
datasource_publish.py.zip
I wrote this issue report on the community forums, (post):
I am having trouble getting a data source published through the REST API.
The resulting error is 400011: Bad Request.
If I check the request against the 3.0 REST API XSD, it is valid:
According to XML Spy at least.
I changed the request_factory.py to do this:
class DatasourceRequest(object):
def _generate_xml(self, datasource_item, connection_credentials=None, connections=None):
xml_request = ET.Element('tsRequest')
datasource_element = ET.SubElement(xml_request, 'datasource')
datasource_element.attrib['name'] = datasource_item.name
if connection_credentials is not None and connections is not None:
raise RuntimeError('You cannot set both
connectionsandconnection_credentials')if connection_credentials:
credentials_element = ET.SubElement(datasource_element, 'connectionCredentials')
credentials_element.attrib['name'] = connection_credentials.name
credentials_element.attrib['password'] = connection_credentials.password
credentials_element.attrib['embed'] = 'true' if connection_credentials.embed else 'false'
if connection_credentials.oauth:
credentials_element.attrib['oAuth'] = 'true'
project_element = ET.SubElement(datasource_element, 'project')
project_element.attrib['id'] = datasource_item.project_id
The fix is to have the project definition come after the credentials. Before this change, the request was not valid according to the XSD.
Overall, I am trying to achieve this:
Script is attached.
datasource_publish.py.zip