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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Get Request, how to use form-data with GET Request in the Thingworx

pshashipreetham
17-Peridot

Get Request, how to use form-data with GET Request in the Thingworx

Hi there,

Trying to do the Get Request with the Form Data but that is not working in the TWX. But in the PostMan, it gives me an 200 Ok Response.

Postman Form-Data: 

psp316r_0-1655920050769.png

How this Form data can be used in the Get Request in Thingworx Service.

@slangley 

Thanks,
Shashi.

Shashi Preetham
1 ACCEPTED SOLUTION

Accepted Solutions

This is fixed by following code 

var TableData = me.GetDataTableEntries({
    maxItems: undefined /* NUMBER {"defaultValue":500} */
});

var content = "grant_type=" + TableData.grant_type + "&client_id=" + TableData.client_id + "&client_secret=" + TableData.client_secret;

params = {
    proxyScheme: "https" /* STRING {"defaultValue":"http"} */ ,
    url: "https://***********" /* STRING */ ,
    content: content /* STRING */ ,
    contentType: "application/x-www-form-urlencoded" /* STRING */ ,
};

// response : STRING
response = Resources["ContentLoaderFunctions"].PostText(params);
result = JSON.parse(response);
Shashi Preetham

View solution in original post

2 REPLIES 2

 This is Thingworx Service Code, But doesn't work.

 

var table = Resources["InfoTableFunctions"].CreateInfoTable();
table.AddField({name: "form-data", baseType: "JSON"});
table.AddRow({
        "form-data" : 
        {
            grant_type : "*********",
            client_id : "*********"",
            client_secret : "*********"",
            resource : "*********""   
        }
});

let params = {
	proxyScheme: "https" /* STRING {"defaultValue":"http"} */,
	headers: {"Content-Type" : "multipart/form-data", "Accept": "*/*"} /* JSON */,
	ignoreSSLErrors: undefined /* BOOLEAN */,
	useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
	partsToSend: table /* INFOTABLE */,
	workstation: undefined /* STRING {"defaultValue":""} */,
	useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
	repository: undefined /* STRING */,
	proxyHost: undefined /* STRING {"defaultValue":""} */,
	url: "*********"" /* STRING */,
	timeout: undefined /* NUMBER {"defaultValue":60} */,
	proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
	password: undefined /* STRING */,
	pathOnRepository: undefined /* STRING */,
	domain: undefined /* STRING {"defaultValue":""} */,
	username: undefined /* STRING */
};

// result: JSON
let result = Resources["ContentLoaderFunctions"].PostMultipart(params);

Shashi Preetham

This is fixed by following code 

var TableData = me.GetDataTableEntries({
    maxItems: undefined /* NUMBER {"defaultValue":500} */
});

var content = "grant_type=" + TableData.grant_type + "&client_id=" + TableData.client_id + "&client_secret=" + TableData.client_secret;

params = {
    proxyScheme: "https" /* STRING {"defaultValue":"http"} */ ,
    url: "https://***********" /* STRING */ ,
    content: content /* STRING */ ,
    contentType: "application/x-www-form-urlencoded" /* STRING */ ,
};

// response : STRING
response = Resources["ContentLoaderFunctions"].PostText(params);
result = JSON.parse(response);
Shashi Preetham
Top Tags