Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I'm trying to figure out where the different aspects of a call to an API would go. For example, the API key or the web address of the API. Also, what is the purpose of the username and password? Is that supposed to be the username and password of your API's account? Also, where do I get the Authorization Server ID if my server is hosted on PTC's cloud service? What are the CSRF settings? What do I do with the Authorization Server Scopes Settings? I found the PTC Help Center article about this, but it wasn't very helpful. Thanks in advance.
Hi Ike@ACE
Please provide more details on what you're trying to call. Is this an API you're trying to call from a client to the ThingWorx platform, or are you trying to run javascript in ThingWorx for connecting to an external system?
Regards.
--Sharon
In case, you are unaware, there is a Base Thing Template called Http Connector. If you view the different aspects of tabs of that type of Thing, you'll find the properties I'm talking about.
Hello Ike@ACE ,
Have you looked at the tool https://www.postman.com/ which allows you to exercise a REST API to determine how to structure your inputs and what gets returned.
For example if you wanted to get information from ThingWorx Thing by running a service you could create a POST transaction in Postman. The header would need to contain key/value information.
appKey, Content-type, Accept.
The appKey has a value which is defined in ThingWorx. This is how you identify yourself to ThingWorx as an authorized person to make requests.
The Content-type has a value of "application/json" which tells the interface how to communite
The Accept identifies what type of information you are looking to accept in my test case "text/html".
The Cross-site request forgery (CSRF) is information to help you protect from a REST API.
A common defense against CSRF attacks is to use synchronized tokens. However, ThingWorx uses an alternate approach and instead routes all requests through a strict content type filter. This approach is equally secure while being more appropriate for a stateless implementation.
Are you trying to make REST API calls into ThingWorx or have ThingWorx make calls into a REST API. I have done some of both. Let me know if any of this information helps. Postman is a great tool to work out the necessary configuration.
Regards
Peter
Hi Peter,
I also have this problem and have never done it before. I will have ThingWorx make calls into a REST API from POSTMAN / MarineTraffic.
Regards
AA
Currently, I'm trying to route the Climacell API through Thingworx and then into an AR experience created with Vuforia Studio. This will end up serving the purpose of allowing two different users in two different locations across the country to use the same experience, but get different results based on their location. It will also allow me to edit the Climacell call without having to go through every experience that uses it and edit the code. I can just edit the Thingworx service, instead.
Hello Ike@ACE ,
Since you are working with a REST API, which you are trying to access from ThingWorx.
You can use Postman to test making a call to the REST API. If you have a API call which gets general information about the site it will be a "GET" transaction. Postman lets you see the response and verify that you have the various fields correctly specified.
For this transaction it returns a JSON object. From ThingWorx you can create a service something below:
try {
var params = {
url: 'http://<REST API WebSite>/<API Function>'
};
var result = Resources["ContentLoaderFunctions"].GetText(params);
var jsonResult = JSON.parse(result);
result = result;
}
} catch(error) {
logger.error("<REST API WebSite>.GetSiteRequest(): Error Calling GET Request - "
+ error.message);
}
This function will just return the text, that was returned from the REST API call. You will need to expand and update to meet your needs.
Let me know if this is the information you are trying to locate. If you can provide more information I may be able to provide more specific answers.
Regards,
Peter
There is a base template for Things in Thingworx called the Http Connector. I am asking about how to use this specific thing. I can already make a call to the ClimaCell API into Vuforia Studio no problem. In fact, the API's resources give you the exact code that you need to do so. What I want is to route it through Thingworx for reusability. The Http Connector is, I think, exactly what I'm looking for. What I am asking for is information on how to get this type of Thing to work. Thanks
Hi Ike@ACE.
If you have resolved your issue with help from one of the previous responses, please mark the appropriate one as the Accepted Solution for the benefit of others with the same problem.
Regards.
--Sharon