It took me _forever_ to figure this out. I abandoned all hope with the v1 REST route when none of the examples I found worked, including one sent to me by Jaspersoft support. Then on to v2! The docs are sorely lacking. This was the magic sauce to get it to finally work:
Important points:
- Use POST /rest_v2/resources/path/to/domain
- Request content type "multipart/form-data"
- "resource" content type "application/repository.semanticLayerDataSource+json" (assuming json)
- "resource" sent as content instead of file
- "resource" uses "schemaFile" property
Hopefully I can save someone else the untold hours I wasted!
Munged request below:
--
POST http://localhost/jasperserver-pro/rest_v2/resources/path/to/domain HTTP/1.1
Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml, text/xml
Content-Type: multipart/form-data; boundary=-----------------------------28947758029299
Host: localhost
Content-Length: 393979
Accept-Encoding: gzip, deflate
-------------------------------28947758029299
Content-Type: application/repository.semanticLayerDataSource+json; charset=UTF-8
Content-Disposition: form-data; name="resource"
{
"dataSource": {
"dataSourceReference": {
"uri": "/path/to/connection"
}
},
"schema": {
"schemaFile": {
"label": "My_schema",
"description": "My_schema",
"type": "xml"
}
},
"label": "A domain"
}
-------------------------------28947758029299
Content-Disposition: form-data; name="schema"; filename="schema.xml"
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0" encoding="utf-8"?>
<schema version="1.0" xmlns="http://www.jaspersoft.com/2007/SL/XMLSchema">
[...rest of schema...]
</schema>
-------------------------------28947758029299--