Skip to main content
5-Regular Member
November 1, 2023
Solved

JSON POST to Teams webhook

  • November 1, 2023
  • 1 reply
  • 1837 views

Hello,

 

Wondering if anyone can see any issue with this.  When putting the same things into SoapUI, everything goes thru fine......but when using content loader function postJSON it just times out.

 

// Define the data you want to send
var messageData =
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "0072C6",
"summary": "ThingWorx Data Update",
"sections": [
{
"activityTitle": "Data Update",
"activitySubtitle": "Timestamp: " + new Date().toUTCString(),
"facts": [
{
"name": "Sensor Name",
"value": "Sensor XYZ"
},
{
"name": "Value",
"value": "42.0"
}
]
}
]
};

let postData = JSON.stringify(messageData);

// Define the parameters for the HTTP POST request
var params = {
url: "https://generalmotors.webhook.office.com/webhookb2/4362b7f2-bfdd-48b0-b8f9-63637259d95b@5de110f8-2e0f-4d45-891d-bcf2218e253d/IncomingWebhook/blahblah", // Replace with your Microsoft Teams webhook URL
headers: {"Content-Type": "application/json"},
content: postData
};

// Send the data to the Teams webhook
result = Resources["ContentLoaderFunctions"].PostJSON(params);

 

 

 

 

 

 

Best answer by VladimirRosu_116627

The key aspect to remember here is that whatever tests you do, should be done from the same baseline.

It does not matter if your SOAPUI call succeeded in your laptop, if you're trying the same call from another machine that does not have the same connectivity as yours. You are now in the situation where you need to understand what are the differences between the machine where you executed the SOAPUI call and the ThingWorx machine, and most certainly, it's the lack of internet access.

As Velkumar said, you're trying to access an internet URL in that snippet (unless you have a hosts mapping to an internal IP address in your laptop).

1 reply

19-Tanzanite
November 2, 2023

Hi @CL_9986028 

 

Could you please check whether Thingworx Instance has access to the Internet. Time-out usually happens whenever the server cannot reach a specific endpoint. 

 

Try to consume API directly from the server using any REST Clients (Postman, Insomnia).

 

Also, try to access some public API ( Reqres - A hosted REST-API ready to respond to your AJAX requests ) from Thingworx.

 

/VR

5-Regular Member
November 2, 2023

The thingworx instance does not have internet access.......but our teams servers are hosted internally I believe, so would i still need internet access if everything is on the intranet?

19-Tanzanite
November 3, 2023

Hi @CL_9986028 

 

I don't think Teams can be hosted in On Premise Server. Based on Webhook which ends with office.com that requires internet access.

 

https://learn.microsoft.com/en-us/answers/questions/1183766/can-teams-be-installed-on-a-private-cloud-or-on-pr

/VR