I'm trying to automate the process of setting up a Workspace, PostGIS Data Store and Layer in GeoServer using the GeoServer REST API.
Using the excellent answer in Create a Layer in GeoServer using REST I'm able to do this, with one sticking point. When I create the workspace using this code...
import requests, json
headers = {'Content-Type': 'application/json'}
auth = ('admin', 'geoserver')
url = "http://<my_geoserver>:8080/geoserver/rest/workspaces"
data = {"workspace": {"name": "blah"}}
r = requests.post(url, headers=headers, auth=auth, data=json.dumps(data))
... the Services are all unchecked on the newly created Workspace:
According to How to set up a Workspace setting in Geoserver using Curl this is a missing feature in the GeoServer REST API.
Given that the Services are unchecked, I'm unable to publish a layer via the GeoServer REST API:
url = 'http://<my_geoserver>:8080/geoserver/rest/workspaces/<workspaceName>/datastores/<dataStoreName>/featuretypes/'
data = {"featureType": {"name": "<layerName>","srs": "EPSG:4326","enabled": "true","store": {"@class": "dataStore","name": "<workspaceName>:<dataStoreName>"}}}
r = requests.post(url, headers=headers, auth=auth, data=json.dumps(data))
as the API responds with :Schema 'http://<workspaceName>:<layerName>' does not exist
.
If I manually select the 4 Services checkboxes on the newly created Workspace, then re-run the code to create a layer, the Layer is created without error.
Is it possible to completely automate the process of creating a Workspace and Datastore, then creating Layers within that Datastore and Workspace, via the GeoServer REST API?