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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

REST API issue in Eclipse

CHASEONHO
18-Opal

REST API issue in Eclipse

hello~

I have found through the web browser that I can change the property value of THING with the REST API.

So how do I PUT or POST to the REST API in Eclipse?

I've referenced the community's POSTing via a REST call in Java, but it does not work.

Note: POST succeeded but not PUT. I did not make any code changes.

[context: com.thingworx.webservices.context.HttpExecutionContext@49f70e14] [message: JSON Content for said Not Not ValidProperties]

said is a property of restapi Thing.

We have encountered these issues while considering the rest method to transmit data from RS485 communication module.

How do I fix it?

ACCEPTED SOLUTION

Accepted Solutions

Usually I test REST services using Postman | API Development Environment


If you want to use Eclipse one way will be to create simple REST client as mentioned in this post POSTing via a REST call in Java you said that doesn't work.

According to Javadoc HttpURLConnection (Java Platform SE 8 the HttpURLConnection.setRequestMethod() supports GET POST HEAD OPTIONS PUT DELETE TRACE so you will need to provide more details.


--Marek

View solution in original post

3 REPLIES 3

in Additional

how to use GET method in Eclipse?

Usually I test REST services using Postman | API Development Environment


If you want to use Eclipse one way will be to create simple REST client as mentioned in this post POSTing via a REST call in Java you said that doesn't work.

According to Javadoc HttpURLConnection (Java Platform SE 8 the HttpURLConnection.setRequestMethod() supports GET POST HEAD OPTIONS PUT DELETE TRACE so you will need to provide more details.


--Marek

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Rest {
	/**
	 * @throws IOException 
	 * @brief Get some information from the server
	 */
	void  Get() throws IOException {
		OkHttpClient client = new OkHttpClient();
		Request request = new Request.Builder()
				.url("https://academic.cloud.thingworx.com/Thingworx/Things/")
				.get()
				.addHeader("appKey", "XXXXXXXXXXXXXX")
				.addHeader("Content-Type", "application/json")
				.addHeader("Accept", "application/json")
				.addHeader("Cache-Control", "no-cache")
				.addHeader("Token", "XXXXXXXXXXXXXXXX")
				.build();
		Response response = client.newCall(request).execute();
		System.out.println(response.body().string());
	}

for the xxxxxxxx insert the appkey you did create in the thingworx platform…..

 

import using maven pom.xml …..the following packages

		<dependency>
			<groupId>com.squareup.okio</groupId>
			<artifactId>okio</artifactId>
			<version>2.0.0-RC1</version>
		</dependency>
		<dependency>
			<groupId>com.squareup.okhttp3</groupId>
			<artifactId>okhttp</artifactId>
			<version>3.11.0</version>
		</dependency>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-stdlib</artifactId>
			<version>1.2.61</version>
		</dependency>
		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-stdlib-common</artifactId>
			<version>1.2.61</version>
		</dependency>

enjoy…..the example is using the rest var get….the same can be accomplished with put...note that other inputs are required therefore….

 

Announcements


Top Tags