Hi,
I like to know how to create a new document in ProjectWise using web services gateway API 1.3. We have no problem to deal with existing documents, such as check in/out. Any help is appreciated.
James
There is a post sample in the Bentley Web Services Gateway (WSG) API help documentation. Expand the "Click to toggle examples" link for the post method:
POST v1.2/DataSources/{dataSource}/Objects/{class}?parentClass={parentClass}&parentObjectId={parentObjectId}
The WSG API is located here for convenience, just download and then open.
HTH,Bob
Bob,
The Web API document is what we have referenced. To make it simple, we use the following code to create a new document without attaching any physical file. Here is the code:
{
string cmd = “https://site name/BentleyWebServices/v1.3/datasources/pw.MTA_PW_DATA/Objects/Document?parentClass=Project&parentObjectId=0d2dd206-0f6f-4657-8283-9ab912028b29”;
using (WebClient client = new WebClient())
client.Credentials = new System.Net.NetworkCredential(Admin, Password); // user and password
Dictionary<string, object> formData = new Dictionary<string, object>();
formData["name"] = name;
formData["description"] = description;
var jss = new JavaScriptSerializer();
string val = jss.Serialize(formData);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = client.UploadString(cmd, "POST", val);
dynamic result = jss.Deserialize<dynamic>(json);
documentId = (string)(result["id"]);
}
return documentId;
catch (WebException e)
string error = e.Message;
After UploadString call, we got “The remote server returned an error: (400) Bad Request.”
Thanks,
If you are not already, I recommend validating web service query strings using the Google Chrome browser and a JSON/RESTful client plugin like: "Postman" or "Advanced REST client". if the URL is constructed properly (no typos), the server is configured properly (install, OS, and network permissions all good), and the user/service (IIS) authentication permissions are in order; you should be good. A REST client plugin helps make troubleshooting URL integrity and IIS permissions much easier.
I also recommend starting off providing a simple data source query to confirm a good starting basis of the URL construction and validation of any permissions before URLs get to complex; like: ( https://mobilesamples.bentley.com/ws/v1.2/datasources )
Answer Verified By: Jshiu
Thank you for pointing us to the right direction. The issue is resolved.
-James
Glad I could be of assistance. Have a good day!
HI Robert, I checked the WDG API link you have posted: communities.bentley.com/.../245045.aspx and I get an 'Access Denied' error. Is there another login required to access it aside from the community credentials? Thanks! Regards, Bernadette