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

ThingWorx Navigate is now Windchill Navigate Learn More

Translate the entire conversation x

How to Authenticate the API for Windchill Odata connector in Thingworx when using SSO Authentication

VV_14105315
4-Participant

How to Authenticate the API for Windchill Odata connector in Thingworx when using SSO Authentication

Hi Folks,

 

I have a requirement to download the files of Windchill objects into Thingworx repository. I am getting the Link of files inside Thingworx using Odata Connectors. I am able to generate the file in Repository but when I try to open the file getting error "Failed to load PDF document."

 

Below is the code I am using :

// result: JSON
let inputJson = Things["ptc-windchill-integration-connector"].downloadAsZip({
respondWithZip: false /* BOOLEAN {"dataShape":""} */,
$expand: undefined /* STRING {"dataShape":""} */,
    objectId: <objectId>
});
 
// result: JSON
let csrf = Things["Thing.ODataConnector.ProdMgmt_TH"].GetCSRFToken({
$select: undefined /* STRING {"dataShape":""} */
});
 
 
    item = inputJson.items[0];
let params = {
url: <file_url> /* STRING */ ,
headers: {
"CSRF_NONCE": <Nonce token>,
                "Accept": "*/*",
                "X-Requested-With": "XMLHttpRequest"
}
        };
// result: BLOB
let binaryContent = Resources["ContentLoaderFunctions"].LoadBinary(params);
    result = binaryContent;
    
    let fullPath = "/test4/" + item.name;
    Things["SupportRepository"].SaveBinary({
path: fullPath /* STRING */,
content: binaryContent /* BLOB */
});
 
What is wrong in my code to authenticate it while downloading it in Thingworx Repository.
 
Thanks in advance.
 
Regards,
VV
 
 
1 REPLY 1

Hello VV,

 

You should be getting the CSRF_NONCE token first and then pass it to subsequent calls - see example bellow:

let ParamA = {            
    url: Windchill_URL + "/servlet/odata/v3/PTC/GetCSRFToken()",
    ...
};    
const NONCE_VALUE = Resources["ContentLoaderFunctions"].GetJSON(ParamA);
...
let ParamB = {            
    ...
    headers: {
        ...
        CSRF_NONCE: NONCE_VALUE
    }
};
result = Resources["ContentLoaderFunctions"].PostJSON(ParamB);

 If you still get some error it would be helpful if you provide ThingWorx/WC log snippets.

Announcements


Top Tags