cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

CreoJs HTTP POST request issue

ThierryLP
5-Regular Member

CreoJs HTTP POST request issue

Good afternoon
I am using Creo Parametric Release 8.0 and Datecode8.0.7.0

I' m using CreoJs in order to automate some tasks in Creo.
From CreoJs, I'm trying to make a call to Windchill REST services.
It works well for a GET request by using "downloadJSON" function from Additional API Features Introduced in Creo.JS in CreoJs user guide.
My issue is when I want to do a POST request.
I use "uploadJSON" function to be able to send a JSON object with body definition and the nonce token in the header.
It always return an Invalid Nonce token error.

Is someone could help me on the correct use of the uploadJSON function to send a POST request with headers?
Or what are built-in function of CreoJs to perform a POST request?

Here are the errors that I faced

"statusMessage":"400: {\"error\":{\"code\":\"INVALID_NONCE\",\"message\":\"A potential security problem was detected. Refresh the page and try again. If the problem persists, contact your administrator.\"}}"

2 REPLIES 2

The above use case may lack some details, but it seems to be an intentional error message. 

 

Have you tried this solution:

Use the GetCSRFToken() function to get the token which is required to be passed as a request header

 

as described in this case solution article:

CS312447 Executing a POST request in Windchill REST Services results in a "INVALID_NONCE" error in Windchill PDMLink

 

and here: "Function to Get the Value of Nonce Token" and "Fetching a NONCE Token from a Service" sections of the Windchill REST Services User's Guide

ThierryLP
5-Regular Member
(To:MichaelW)

Thanks for your update.

I'm aware of the fact the POST request needs an autentication with a NONCE TOKEN.
Using a browser, I'm able to perform POST request to REST services with fetch method. I first requests a token, add it to the headers of the POST request and send it.

I'm not able to do such thing from the CreoJS environment as the fetch method is not available.

I request a token with "downloadJSON" method and I get it without problems.

According to documentation, equivalent function in CreoJS for POSTING data should be "uploadJSON", but it seems that it give not the possibility to add the token to the headers.

Am I right?

 

Here is a piece of my code:

	let __server = "https://xxxxxxxxxxx.fr/Windchill";
	
	
	let token = downloadJSON(__server + "/servlet/odata/PTC/GetCSRFToken()");
	
	let json = {
		method: "POST", // *GET, POST, PUT, DELETE, etc.
    headers: {
      "Content-Type": "application/json",
      'CSRF_NONCE': token.NonceValue,
    },
    body: {}
	}
	
	let str = uploadJSON(__server + "/servlet/odata/CADDocumentMgmt/CADDocuments('OR:wt.epm.EPMDocument:29501222529')/PTC.CADDocumentMgmt.GetStructure?$expand=Components($levels=max)",json);

 

Announcements
NEW Creo+ Topics: PTC Control Center and Creo+ Portal


Top Tags