メールの受信:テンプレート

Use Template

プレースホルダーを埋めた送信用の件名と本文を取得し、使用回数を数えます。

POSThttps://g.sendcorex.com/v1command: use_template

send_email、reply、schedule_sendもtemplate_idを直接受け付けます。送信前に本文を編集したい場合にこのコマンドを使います。

引数

  • idstring必須

    template_id。

  • to_namestring任意

    {first_name}、{last_name}、{name}を埋めます。

  • to_emailstring任意

    {email}を埋めます。

  • variablesobject任意

    独自のプレースホルダー:{ "company": "Acme" }で{company}が埋まります。

クイックスタート

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "use_template",
        args: {
          id: "Vj0xVFBMMDAx",
          to_name: "Ana Costa",
          variables: {
            company: "Acme"
          }
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

レスポンス

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "use_template",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "id": "Vj0xVFBMMDAx",
        "subject": "Our pricing",
        "html": "<p>Hi Ana,</p><p>Here is our pricing…</p>"
      }
    }
  ]
}

エラー

HTTPレベルのエラーはtype、code、messageを返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

  • 401TOKEN_EXPIRED

    access tokenの有効期限が切れました。Refresh Tokenを呼んでリクエストを繰り返してください。

  • 401INVALID_TOKEN

    トークンの形式が不正、不明、または取り消されています。

  • 429RATE_LIMITED

    同じIP + メールボックスで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。

  • CMDINVALID_ARGS

    必須の引数がないか不正です。

  • CMDNOT_FOUND

    このトークンでは、そのメッセージ、スレッド、フォルダーは存在しません。

  • CMDINTERNAL

    サーバーエラー。詳細はサーバーのログにのみ記録されます。