The algorithm I have so far is basically this:

  1. Create a sddraft from a mxd file (using arcpy.CreateMapSDDraft().
  2. Stage sddraft into a sd file (using arcpy.StageService_server().
  3. Upload sd file to ArcGIS server over REST.
    1. There's a little dance that has to happen due to the fact that we use web-adaptor and have to redirect all requests to a single-sign-on server first for authentication, before forwarding the intended request to the intended destination.
  4. Call createService on ArcGIS server's REST API, pointing to the uploaded sd file.
    1. This happens in the same http session, so no need to go through the authentication dance again.

The fourth step manages to create the service, but startup fails due to Invalid file. The only documentation for the createService endpoint that I could find is this, and I can only surmise that the endpoint only accepts the old and deprecated msd file, but not the newer sd file. If that's the case, what endpoint am I supposed to hit for creating a service from a sd file? Note that arcpy.UploadServiceDefinition() isn't an option for us due to the fact that authentication is handled elsewhere from the ArcGIS server.

  • What does CanCreateService return? – Kirk Kuykendall Oct 4 '19 at 1:47
  • Status code 500: ArrayOutOfBoundsException. – CJ Virtucio Oct 4 '19 at 12:26

Finally got a working solution.

First off, if you're using a webadaptor front-end, the base URI that you'll be using will likely be something like: https://<your-domain>/web-adaptor

So paths to endpoints as defined in the official documentation will be relative to that base URI, e.g. the absolute path to the file upload endpoint would be https://<your-domain>/web-adaptor/admin/uploads/upload.

Now that's out of the way, here's the algorithm for publishing a service (you'll need an http library like the python requests module that also allows you to make calls in a single session).

(all calls here are assumed to be made with a given session object)

  1. Make your authentication calls with whatever your SSO solution is.
  2. Upload your service definition file in POST request to /admin/uploads/upload, with a parameter {"f": "json"}. You'll receive the ID that the server generates for the file in the response as itemID.
  3. The ArcGIS Server will create a service configuration file for your service definition. Grab it by making a GET request to /admin/uploads/<itemID>/serviceconfiguration.json?f=json.
  4. Start a job to create the service by making POST request to /rest/services/System/PublishingTools/GPServer/Publish%20Service%20Definition/submitJob, passing the ff. JSON object in the body:

  "in_sdp_id": <itemID>,

  "in_config_overwrite": <the content of the serviceconfiguration.json from step 3>,

  "f": "json"


You'll receive the jobID in the response.

You can repeatedly make a GET request to /rest/services/System/PublishingTools/GPServer/Publish Service Definition/jobs/<jobID>?f=json to check the status if your job. You'll know it's done once jobStatus is set to esriJobSucceeded. The URL to your service will also be available in the results.out_rest_svc_url.paramUrl property.

  • could you post some of your python code? I am having a hard time getting the requests/session to work... – fallingdog Dec 12 '19 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.