Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Based on the current REST API I was able to upload primary content following some examples using the uploadstage1action and uploadstage3action. However, my use case is to provide an integration that allows to update the primary content. Clearly this can be done easily via the web UI.
There is no obvious method using the REST API. Using the example on a document which already has primary content the uploadstage3action fails with indication that a document cannot have more than 1 primary content.
There are no methods to delete the current primary content, nor to update (PUT/PATCH methods).
This seems like a very normal use case for an integration, and I'm wondering what I'm missing here.
I'm testing with windchill 12, WRS Document Management Domain, API Version 5
Solved! Go to Solution.
@WL_10778105 @FransB I have tried out a custom REST API implementation to update the primary content. You can change the code according to your needs.
Hi FB_8069857,
Thank you for your question.
I’d like to recommend to bring more details and context to your initial inquiry. Product name, version details etc.
It also helps to have screenshot(s) to better understand what you are trying to do in your process.
This will increase your chances to receive meaningful help from other Community members.
Regards,
Vivek N
Community Moderation Team.
Hi N Vivek,
I'm building an external tool that communicates with Windchill 12 using the ODATA REST API.
This REST API and specifically PTC Document Management Domain API Version 5 provides endpoints for all sorts of actions on documents, including setting and retrieving primary content.
There are several examples on how the upload content (primary/attachments), which I have followed and am able to upload primary content for a document that has not yet primary content. However when the WTDocument already has primary content this method of upload fails, with a message that primary content already exists.
There is no endpoint identified in the documentation that describes how to remove existing primary content, or otherwise prepare for a new upload. Clearly updating primary content via the Windchill web interface is no problem and very easy to do.
The working example for uploading new primary content can be found here:
Upload file in a WindChill document - OData REST A... - PTC Community
The REST interface with its documentation (if enabled) can be found via;
Hi @FransB
I know it is not solution, you will need to study how to customize WRS
You can create own WRS api with own function and write a code that do what you need. Just update the primary content.
You need to customize rest api domain add a endpoint and JSHooks where you write java class code that update the primary content as you need.
This is just idea how it could work
here is knowledge hub how to customize WRS
CS183488 - Windchill PLM REST Services - Customization
and here is example how the end point with JSHooks is used
CS389663 - Example of Custom Logic and JSHooks in Windchill Rest Services
hope this can help.
PetrH
Any luck in solving this? I am running into the same issue on Windchill v12.1.2.4. I am just a user, not an admin of our Windchill instance. I need to be able to update primary document content programmatically via the REST API. Currently this is failing with the message `{"error":{"code":null,"message":"Can not add more than one primary content to the object."}}` when hitting the endpoint `Windchill/servlet/odata/DocMgmt/Documents('<OID>')/PTC.DocMgmt.UploadStage3Action`.
@WL_10778105 @FransB I have tried out a custom REST API implementation to update the primary content. You can change the code according to your needs.
Thanks for spending this effort and showing how it can be done. I'm currently not in a position to update the REST API. I will try my best to get this kind of access and then try your solution.
It does not appear in the Windchill REST API Documentation page, but you can delete primary content using this endpoint. Then you can attach the new primary content.
DELETE /Windchill/servlet/odata/v5/DocMgmt/Documents('OR:wt.doc.WTDocument:XXXX')/PrimaryContent