Hi,
We've noticed today that we get InternalServerError when we're trying to Publish a file and lacks the proper accesslevel in the project.(Not set as Document Manager).
public static HttpStatusCode Publish(string ticket, string project_id, string directory, string filename, byte[] bytes, string document_id, string tags, string caption) { // (1) Build request var client = new RestClient(); client.BaseUrl = new System.Uri(Settings.baseUrl); // Set resource or end point var request = new RestRequest(); request.Resource = "/api/library/publish"; request.Method = Method.POST; // Add parameters request.AddParameter("ticket", ticket); request.AddParameter("project_id", project_id); request.AddParameter("directory", directory); request.AddParameter("filename", filename); // Optional parameters if (!string.IsNullOrEmpty(document_id)) request.AddParameter("document_id", document_id); request.AddParameter("tags", tags); if (!string.IsNullOrEmpty(caption)) request.AddParameter("caption", caption); // Add Files request.AddFile("Filedata", bytes, filename); // (2) Execute request and get response IRestResponse response = client.Execute(request); // Save response. This is to see the response for our learning. Settings.m_lastResponse = response; return response.StatusCode; }
What would be the proper way to ensure/check the access either before upload or maybe get a proper response like "Unable to publish file. Insufficient user rights" or something so I can actually handle it?
Hi,
We've noticed today that we get InternalServerError when we're trying to Publish a file and lacks the proper accesslevel in the project.(Not set as Document Manager).
public static HttpStatusCode Publish(string ticket, string project_id, string directory, string filename, byte[] bytes, string document_id, string tags, string caption) { // (1) Build request var client = new RestClient(); client.BaseUrl = new System.Uri(Settings.baseUrl); // Set resource or end point var request = new RestRequest(); request.Resource = "/api/library/publish"; request.Method = Method.POST; // Add parameters request.AddParameter("ticket", ticket); request.AddParameter("project_id", project_id); request.AddParameter("directory", directory); request.AddParameter("filename", filename); // Optional parameters if (!string.IsNullOrEmpty(document_id)) request.AddParameter("document_id", document_id); request.AddParameter("tags", tags); if (!string.IsNullOrEmpty(caption)) request.AddParameter("caption", caption); // Add Files request.AddFile("Filedata", bytes, filename); // (2) Execute request and get response IRestResponse response = client.Execute(request); // Save response. This is to see the response for our learning. Settings.m_lastResponse = response; return response.StatusCode; }
What would be the proper way to ensure/check the access either before upload or maybe get a proper response like "Unable to publish file. Insufficient user rights" or something so I can actually handle it?
Hi clwi,
It would be nicer to have an error message saying the nature of failure than internal error, wouldn't it?
I see two calls, fieldapi/admin/v1/users and api/v1/projects/{project_id}/users return a list of users with roles:
https://bim360field.autodesk.com/apidoc/index.html#admin_api_method_6
https://bim360field.autodesk.com/apidoc/index.html#api/v1/project_users_method_1
Maybe what you can do will be to check the individual's role there after the user login and use that info.
Hi clwi,
It would be nicer to have an error message saying the nature of failure than internal error, wouldn't it?
I see two calls, fieldapi/admin/v1/users and api/v1/projects/{project_id}/users return a list of users with roles:
https://bim360field.autodesk.com/apidoc/index.html#admin_api_method_6
https://bim360field.autodesk.com/apidoc/index.html#api/v1/project_users_method_1
Maybe what you can do will be to check the individual's role there after the user login and use that info.
(sorry please ignore this one)
(sorry please ignore this one)
Hi clwi,
if you are getting unauthorized, maybe you don't have an access right for the user data. That will be a limitation.
Also, just in case, if you are having a problem just to call /users, could you make sure you are passing project_id as a URL parameter, not a form parameter? e.g., using RESTShape, it will look like this:
>>>>
request.Resource = "/api/v1/projects/{project_id}/users
request.AddUrlSegment("project_id", project_id);
<<<<
Hi clwi,
if you are getting unauthorized, maybe you don't have an access right for the user data. That will be a limitation.
Also, just in case, if you are having a problem just to call /users, could you make sure you are passing project_id as a URL parameter, not a form parameter? e.g., using RESTShape, it will look like this:
>>>>
request.Resource = "/api/v1/projects/{project_id}/users
request.AddUrlSegment("project_id", project_id);
<<<<
Hi,
still cannot get it to work.. i'm currently getting NotFound results now...
my current meethod...
public static HttpStatusCode IsDoucmentManager(string ticket, string project_id, string user_id )
{
// (1) Build request
var client = new RestClient();
client.BaseUrl = new System.Uri("https://bim360field.eu.autodesk.com");
// Set resource or end point
var request = new RestRequest();
request.Resource = "/api/v1/projects/{project_id}/users";
request.AddUrlSegment("project_id", project_id);
request.Method = Method.GET;
// Add parameters
request.AddParameter("ticket", ticket);
//request.AddParameter("project_id", project_id);
//request.AddParameter("id", user_id);
// (2) Execute request and get response
IRestResponse response = client.Execute(request);
Settings.m_lastResponse = response;
return response.StatusCode;
}
Any advice?
Hi,
still cannot get it to work.. i'm currently getting NotFound results now...
my current meethod...
public static HttpStatusCode IsDoucmentManager(string ticket, string project_id, string user_id )
{
// (1) Build request
var client = new RestClient();
client.BaseUrl = new System.Uri("https://bim360field.eu.autodesk.com");
// Set resource or end point
var request = new RestRequest();
request.Resource = "/api/v1/projects/{project_id}/users";
request.AddUrlSegment("project_id", project_id);
request.Method = Method.GET;
// Add parameters
request.AddParameter("ticket", ticket);
//request.AddParameter("project_id", project_id);
//request.AddParameter("id", user_id);
// (2) Execute request and get response
IRestResponse response = client.Execute(request);
Settings.m_lastResponse = response;
return response.StatusCode;
}
Any advice?
Hi clwi,
The code looks correct to me.
A few places I can think of as places to check -
Does the current API user has an access to the project pointed by project_id?
You may try as a full access user and see if it works. This may help to separate if the issue is permission/projects with the current user or some where in the logic of the code, for example.
Hi clwi,
The code looks correct to me.
A few places I can think of as places to check -
Does the current API user has an access to the project pointed by project_id?
You may try as a full access user and see if it works. This may help to separate if the issue is permission/projects with the current user or some where in the logic of the code, for example.
Can't find what you're looking for? Ask the community or share your knowledge.