Generate new topics, posts and PM via IFTTT

Want to use IFTTT to create new topics, posts and personal messages? Let’s get started!

Using Maker Webhooks of IFTTT service we can make Discourse API calls. For that we must generate API keys first. You can create API keys from the admin panel at /admin/api/keys.

Also we can generate user specific API keys through user admin pages.

Now create new applet on IFTTT and then choose your favorite trigger service. Now I am using Google Calendar service for example.

Then I am choosing Any new event added trigger.

To connect your trigger with Discourse choose Maker Webhooks as action service and Make a web request action.

Now fill the action fields as below.

  • URL (required): https://discourse.example.com/posts.json

  • Method (required): POST

  • Content Type: application/json

  • Additional Headers:

Api-Key: [YOUR_API_KEY]
Api-Username: [API_USERNAME]

:warning: Important: API credentials must be sent as HTTP headers (Api-Key and Api-Username), not as URL query parameters. Discourse does not accept API key authentication via query parameters on POST requests. IFTTT’s Maker Webhooks service supports custom headers — use the Additional Headers field to add them.

  • Body:
{
 "title": "{{Title}}",
 "raw": "{{Description}}\n\nPlace: {{Where}}\nAt: {{Starts}} - {{Ends}}",
 "category": 4,
 "created_at": "{{CreatedAt}}"
}

In body text you can see many fields with double brackets {{ }}. Those fields (content sources) will vary with every service triggers. Choose it from Ingredient button below.

You can edit title and raw fields in JSON body however you need with surrounded texts. Find category id from your site’s /site.json URL and put it on category field. Now click Create action button to create the applet. After the applet creation it may take some time to be live.

It’s done :sunglasses:. Now a new topic will be created whenever a new event created on your Google Calendar :calendar_spiral:.


To create a post reply to an existing topic instead of new topic creation the body text should be changed as below (topic_id instead of category)

{
 "title": "{{Title}}",
 "raw": "{{Description}}\n\nPlace: {{Where}}\nAt: {{Starts}} - {{Ends}}",
 "topic_id": 4,
 "created_at": "{{CreatedAt}}"
}

To create new personal message

{
 "title": "{{Title}}",
 "raw": "{{Description}}\n\nPlace: {{Where}}\nAt: {{Starts}} - {{Ends}}",
 "target_usernames": "discourse1,discourse2",
 "archetype": "private_message",
 "created_at": "{{CreatedAt}}"
}

In this same method you can make Discourse API requests by any other IFTTT action services.

Last edited by @awesomerobot 2026-06-08T21:52:07Z

Check documentPerform check on document:
22개의 좋아요

이 옵션이 더 이상 무료가 아니고 개발자를 위한 프리미엄으로만 제공되는 건 아닌지 궁금합니다.

1개의 좋아요

Discourse API 문서에 따르면, Api_username과 Api_key는 HTTP 요청 헤더를 통해 전송되어야 합니다. GET 매개변수로 전송하는 것은 작동하지 않습니다.

시해 보았으나 실패했습니다. 따라서 여기에서 안내된 대로 IFTTT를 사용할 수 없었습니다…

그러나 결국 데이터가 Discourse로 올바른 구성으로 전송될 수 있도록 하는 간단한 커스텀 PHP 스크립트를 작성하여 릴레이 훅으로 사용했습니다.

코드
<?php
header('Content-Type: application/json');

// POST 요청인지 확인합니다.
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) {
    echo json_encode(array("error" => 'Request method must be POST!'));
}

// POST 요청의 콘텐츠 타입이 application/json으로 설정되었는지 확인합니다.
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if (strcasecmp($contentType, 'application/json') != 0) {
    echo json_encode(array("error" => 'Content type must be: application/json'));
}

// RAW POST 데이터를 수신합니다.
$content = trim(file_get_contents("php://input"));

// 수신된 RAW POST 데이터를 JSON에서 디코딩하려고 시도합니다.
$payload = json_decode($content, true);

// json_decode가 실패하면 JSON이 유효하지 않습니다.
if (!is_array($payload)) {
    echo json_encode(array("error" => 'Received content contained invalid JSON!'));
    die();
}

if (empty($payload['discourse_endpoint'])) {
    echo json_encode(array("error" => 'Discourse endpoint must be provided in the json body!'));
    die();
}

if (empty($payload['api_key'])) {
    echo json_encode(array("error" => 'Discourse API Key must be provided in the json body!'));
    die();
}

if (empty($payload['api_username'])) {
    echo json_encode(array("error" => 'Discourse API User must be provided in the json body!'));
    die();
}

$discourse_endpoint = $payload['discourse_endpoint'];
$api_key = $payload['api_key'];
$api_user = $payload['api_username'];

unset($payload['discourse_endpoint']);
unset($payload['api_key']);
unset($payload['api_username']);

$data_string = json_encode($payload);

$ch = curl_init($discourse_endpoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    "Api-key: $api_key",
    "Api-username: $api_user",
    'Content-Length: ' . strlen($data_string)
));
$result = curl_exec($ch);

echo $result;

?>

이에 대한 자세한 내용은 여기에서 확인하세요: Generate new topics, posts and PM via Discourse Relay API Script - php - CTC Community Forum

2개의 좋아요

저도 비슷한 상황입니다. Pinboard에서 특정 태그가 달린 항목을 게시하도록 IFTTT 앱렛을 설정하려고 하고 있습니다. (다른 앱렛들은 헤더 항목으로 토큰을 전달할 수 있어 Mastodon에 게시하는 데 문제가 없었습니다.)

제 PHP 실력은 초보 수준이지만, 님의 코드가 어떻게 작동하는지는 충분히 이해합니다. Discourse 서버에 대한 지식이 부족해서 질문드리는데, 이 스크립트를 어디에 배치해야 하나요? CORS 문제를 피하기 위해 같은 서버에 있어야 하나요?

아니면 IFTTT 대신 다른 통합 중간 플랫폼을 고려해 봐야 할까요?

IFTTT에서 요청을 받을 수 있고, curl 함수를 통해 Discourse 인스턴스와 통신할 수 있는 서버에 호스팅되어 있으면 됩니다. 이는 Discourse 웹 인터페이스가 보내는 것과 동일한 유형의 요청을 시작할 뿐입니다. :slight_smile:

1개의 좋아요

감사합니다. Zapier에 접근할 수 있는 것 같고, 이쪽이 더 나은 통합 기능을 제공하는 것 같습니다.