I have a .NET Windows Service which succesfully can make geometry queries to a REST API using token authentication.
When I try to add a feature to a ArcGIS BigData Store using the add features API (https://<featurelayer-url>/addFeatures(POST only)) I get the error message.
{"error":{"code":500,"message":"User does not have the privilege to perform this operation.","details":[]}}
Do I need to add special privileges to the user or how can I get the addFeature call work?
(The call works in the ArcGIS Server Manager web-tool, so that shouldn't be the case though).
This is how I acquire the token:
private string GetToken()
{
try
{
var request = (HttpWebRequest)WebRequest.Create("https://xyz.com/server/tokens/generateToken");
request.Proxy = WebRequest.DefaultWebProxy;
request.Credentials = CredentialCache.DefaultCredentials;
request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
NetworkCredential networkCredential = new NetworkCredential("proxyuser", "pwd");
request.Credentials = networkCredential;
var postData = "username=user";
postData += "&password=pwd";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
return responseString;
}
catch (Exception ex)
{ }
return null;
}
}
// This is how I post the feature
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.Headers["Content-type"] = "application/x-www-form-urlencoded";
client.Encoding = System.Text.Encoding.UTF8;
var collection = new System.Collections.Specialized.NameValueCollection();
collection.Add("f", "json");
collection.Add("features", json);
var response = client.UploadValues(uri, "POST", collection);
MemoryStream stream = new MemoryStream(response);
StreamReader reader = new StreamReader(stream);
string responseStr = reader.ReadToEnd();
}
I had this problem too. Turns out you need an OAuth token and not the token from generateToken. The code I used is here: https://gist.github.com/YikChingTsui/ff6d7b6126db73a77e5845576250177d