I am trying to upload a layer using the GeoServer (2.28) REST API using the Importer extension in python. I ak not not what I am doing wrong.If I use the PUT method when the sld does not exists in an empty workspace, it will load the layer and sld but will not apply the styling. If I reload a second time using the POST method for the same layer and sld in the same workspace the style is applied correctly. below are the code I am using, but I cannot figure out what I am doing wrong:
1.1 To upload a layer - (workspace is empty):
# Step 1: Create import job POST /rest/imports { "import": { "targetWorkspace": { "workspace": { "name": "city" } } } } # Step 2: Upload file to import task POST /rest/imports/{import_id}/tasks Files: towns.shp, towns.shx, towns.dbf (multipart form-data) # Step 3: Execute import POST /rest/imports/{import_id} (no payload) # Step 4: Execute task POST /rest/imports/{import_id}/tasks/{task_id} (no payload) 1.2 The SLD upload handling - (workspace is empty):
# Check if style exists GET /rest/workspaces/city/styles/towns.json # Since workspace is empty, style doesn't exist → CREATE NEW POST /rest/workspaces/city/styles?raw=true&name=towns Content-Type: application/vnd.ogc.sld+xml [SLD XML content as raw bytes] # Assign style to layer PUT /rest/layers/city:towns { "layer": { "defaultStyle": { "name": "towns" }, "enabled": true } } 2.1 To upload a layer - (workspace is not empty):
# Step 1: Create import job (SAME as Scenario 1) POST /rest/imports { "import": { "targetWorkspace": { "workspace": { "name": "city" } } } } # Step 2: Upload file to import task (SAME as Scenario 1) POST /rest/imports/{import_id}/tasks Files: towns.shp, towns.shx, towns.dbf (multipart form-data) # Step 3: Execute import (SAME as Scenario 1) POST /rest/imports/{import_id} (no payload) # Step 4: Execute task (SAME as Scenario 1) POST /rest/imports/{import_id}/tasks/{task_id} (no payload) 2.2 The SLD upload handling - (workspace is not empty)::
# Check if style exists GET /rest/workspaces/city/styles/towns.json # Since workspace already has styles, style likely EXISTS → UPDATE EXISTING PUT /rest/workspaces/city/styles/towns.sld?raw=true Content-Type: application/vnd.ogc.sld+xml [SLD XML content as raw bytes] # Assign style to layer (SAME as Scenario 1) PUT /rest/layers/city:towns { "layer": { "defaultStyle": { "name": "towns" }, "enabled": true } } In code block 1.2; is application/vnd.ogc.sld+xml correct ?