Select to view content in your preferred language

How to create an empty Hosted Feature service using the ArcGIS REST API using API key authentication?

118
5
2 weeks ago
Labels (1)
devdattaTH
Emerging Contributor

I am trying to create an empty Hosted Feature service from my python script using the ArcGIS REST API. I want that service to have multiple layers, and the schema would be dynamically created at creation type.

I thought of using API key authentication, as it would be an internal script, and would run without any human interaction.

I thought that the createService API call (https://developers.arcgis.com/rest/users-groups-and-items/create-service/) would be the right thing to look at. Confusingly, the documentation says: "This endpoint is only accessible to the content owner and members who are assigned the default administrator role. All other members will receive a permissions error when attempting to access this endpoint."

When I tried using this API via postman, I got the error message: ["User '<UserName>' does not have publishing privileges"].

The API key has been created by an account, which has a publisher role, and can create an empty feature service in the WebUI using the New Item >> Create a feature layer>> Define Your Own Layer flow.

For debugging purposes, I checked using oAuth Based authentication, and if I used the access token from there, I could successfully use the createService API call.

But since I need to run the Script in an Automated manner every week, I can't really use an OAuth Based authentication.

What's the right method to make the createService API call using API key authentication?

0 Kudos
5 Replies
MarkTorrey
Esri Contributor

Hi devdattaTH, It sounds like you might need to give your API key additional privileges. From your description, you'll at least want to give it `portal:user:createItem` and `portal:publisher:publishFeatures` personal scope privileges.

https://developers.arcgis.com/documentation/security-and-authentication/api-key-authentication/api-k...

https://developers.arcgis.com/documentation/security-and-authentication/reference/privileges/#privil...

Let us know if this helps...

Thanks,

Mark

0 Kudos
devdattaTH
Emerging Contributor

That is one of the first things I checked, and the key does have both the permissions.

Screenshot 2025-08-05 201302.pngScreenshot 2025-08-05 200826.png

0 Kudos
devdattaTH
Emerging Contributor

One thing I have notices in my testing is that If I use a key from my ArcGIS location platform account (where my account is an admin) the call to createService API does work.

But If I am a user with the publisher role, and create an API key with the shown Privileges, on my organisation's ArcGIS Online account, it does not work.

And as mentioned in the original post, if I use Oauth Based Authentication, and use the access token from that workflow, I can make the api call to createService API

0 Kudos
MarkTorrey
Esri Contributor

What's the user type of your ArcGIS Online account?

0 Kudos
devdattaTH
Emerging Contributor

My user type is Creator:

devdattaTH_0-1754463981530.png

 

0 Kudos