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

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

Shashi_Preetham
16-Pearl

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.

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);

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);

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);
Announcements