# Generate new topics, posts and PM via IFTTT

**URL:** https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336
**Category:** Integrations
**Tags:** how-to, tasks
**Created:** [4월 20, 2017, 4:30오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336 "2017-04-20T16:30:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [4월 20, 2017, 4:30오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/1 "2017-04-20T16:30:45Z")

</div>

Want to use [IFTTT](https://ifttt.com/) to create new topics, posts and personal messages? Let’s get started!

Using [Maker Webhooks](https://ifttt.com/maker_webhooks) of IFTTT service we can make [Discourse API](https://docs.discourse.org) calls. For that we must generate API keys first. You can create API keys from the admin panel at `/admin/api/keys`.

[![](https://global.discourse-cdn.com/meta/optimized/3X/9/1/9165372a47fa7a7f88adf252d9e56f649bf01b6c_1_690x143.png) ](https://global.discourse-cdn.com/meta/optimized/3X/9/1/9165372a47fa7a7f88adf252d9e56f649bf01b6c_1_690x143.png)

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

Now [create new applet](https://ifttt.com/create) on IFTTT and then choose your favorite trigger service. Now I am using [Google Calendar](https://ifttt.com/create/connect-google_calendar?sid=1) service for example.

 ![](https://global.discourse-cdn.com/meta/original/3X/3/4/341b41d93de97b271496b99dcc53d21df4089ac4.png)

Then I am choosing **Any new event added** trigger.

 ![](https://global.discourse-cdn.com/meta/original/3X/a/9/a92552c97474e03de602f8f5b134e4d3929bc76b.png)

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

 ![](https://global.discourse-cdn.com/meta/original/3X/c/9/c9522a31c798594cadafc8f3962b0eb4cccc6a13.png)

Now fill the action fields as below.

- **URL (required):** `https://discourse.example.com/posts.json`

- **Method (required):** `POST`

- **Content Type:** `application/json`

- **Additional Headers:**

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

```

> ⚠ **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:**

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

```

 ![](https://global.discourse-cdn.com/meta/original/3X/7/7/77365735ed9f95d460f2de4c16bcb13dbfda9ea0.png)

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 🕶. Now a new topic will be created whenever a new event created on your Google Calendar 🗓.

* * *

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

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

```

To create new personal message

```plaintext
{
 "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](https://ifttt.com/search/services).

> Last edited by @awesomerobot 2026-06-08T21:52:07Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![eextra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eextra/32/170266_2.png) [@eextra](https://meta.discourse.org/u/eextra)
#### Post date: [4월 17, 2020, 11:22오전 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/2 "2020-04-17T11:22:34Z")

</div>

> [@vinothkannans](#):
>
> 이제 [새로운 앱렛 만들기](https://ifttt.com/create)

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

---

<div class="post-metadata">

### Author: ![b4oshany](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/b4oshany/32/176298_2.png) [@b4oshany](https://meta.discourse.org/u/b4oshany)
#### Post date: [10월 10, 2020, 3:14오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/3 "2020-10-10T15:14:17Z")

</div>

[Discourse API 문서](https://docs.discourse.org/#tag/Posts/paths/~1posts.json/post)에 따르면, `Api_username`과 `Api_key`는 HTTP 요청 헤더를 통해 전송되어야 합니다. GET 매개변수로 전송하는 것은 작동하지 않습니다.

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/f/9fb69f3bc83ad8bff56975b2efc0b3361e91d6b9.png)

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

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

##### 코드

```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](https://community.jamaicans.dev/t/generate-new-topics-posts-and-pm-via-discourse-relay-api-script/176)

---

<div class="post-metadata">

### Author: ![cogdog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cogdog/32/116536_2.png) [@cogdog](https://meta.discourse.org/u/cogdog)
#### Post date: [3월 20, 2023, 3:43오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/4 "2023-03-20T15:43:13Z")

</div>

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

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

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

---

<div class="post-metadata">

### Author: ![ClawdiaWolf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/clawdiawolf/32/262518_2.png) [@ClawdiaWolf](https://meta.discourse.org/u/ClawdiaWolf)
#### Post date: [3월 22, 2023, 12:18오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/5 "2023-03-22T12:18:23Z")

</div>

> [@cogdog](#):
>
> 제 평범한 PHP 실력으로는 여러분의 코드가 어떻게 작동하는지 충분히 이해하지만, Discourse 서버에 대해 잘 모르는 제 입장에서 질문은 다음과 같습니다. 이 스크립트를 어디에 배치해야 하나요? CORS 문제를 피하려면 같은 서버에 있어야 하나요?

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

---

<div class="post-metadata">

### Author: ![cogdog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cogdog/32/116536_2.png) [@cogdog](https://meta.discourse.org/u/cogdog)
#### Post date: [3월 23, 2023, 10:43오후 UTC](https://meta.discourse.org/t/generate-new-topics-posts-and-pm-via-ifttt/61336/6 "2023-03-23T22:43:21Z")

</div>

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