forked from docs/doc-exports
Reviewed-by: Bobkova, Natalia <natalia.bobkova@t-systems.com> Co-authored-by: Zaoxu, Li <lizaoxu@huawei.com> Co-committed-by: Zaoxu, Li <lizaoxu@huawei.com>
151 lines
13 KiB
HTML
151 lines
13 KiB
HTML
<a name="smn_api_54002"></a><a name="smn_api_54002"></a>
|
|
|
|
<h1 class="topictitle1">Publishing Messages Using a Message Structure</h1>
|
|
<div id="body1471602451370"><div class="section" id="smn_api_54002__section2529770119494"><h4 class="sectiontitle">Description</h4><ul id="smn_api_54002__ul33304380203733"><li id="smn_api_54002__li51147505203733">API name<p id="smn_api_54002__p38624841203741"><a name="smn_api_54002__li51147505203733"></a><a name="li51147505203733"></a>Publish</p>
|
|
</li></ul>
|
|
<ul id="smn_api_54002__ul20998054203745"><li id="smn_api_54002__li46884910203750">Function<p id="smn_api_54002__p1766898510217"><a name="smn_api_54002__li46884910203750"></a><a name="li46884910203750"></a>Use the message structure to publish a message to a topic. After the message ID is returned, the message has been saved and is to be pushed to the subscribers of the topic. This API allows you to send different message content to different types of subscribers.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="smn_api_54002__section5419540819494"><h4 class="sectiontitle">URI</h4><ul id="smn_api_54002__ul2775191419494"><li id="smn_api_54002__li4844064019494">URI format<p class="tabletext" id="smn_api_54002__p3331258119494"><a name="smn_api_54002__li4844064019494"></a><a name="li4844064019494"></a>POST /v2/{project_id}/notifications/topics/{topic_urn}/publish</p>
|
|
</li></ul>
|
|
<ul id="smn_api_54002__ul3137777819494"><li id="smn_api_54002__li1396455319494">Parameter description
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="smn_api_54002__table5857211319494" frame="border" border="1" rules="all"><thead align="left"><tr id="smn_api_54002__row2704976919494"><th align="left" class="cellrowborder" valign="top" width="20.48%" id="mcps1.3.2.3.1.1.1.5.1.1"><p id="smn_api_54002__p4354764619494"><strong id="smn_api_54002__b842352706191030">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="19.28%" id="mcps1.3.2.3.1.1.1.5.1.2"><p id="smn_api_54002__p3769841519494"><strong id="smn_api_54002__b593421527191713">Mandatory</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="21.69%" id="mcps1.3.2.3.1.1.1.5.1.3"><p id="smn_api_54002__p3367280619494"><strong id="smn_api_54002__b84235270619112">Type</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="38.550000000000004%" id="mcps1.3.2.3.1.1.1.5.1.4"><p id="smn_api_54002__p4314272819494"><strong id="smn_api_54002__b84235270619115">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="smn_api_54002__row6136344319494"><td class="cellrowborder" valign="top" width="20.48%" headers="mcps1.3.2.3.1.1.1.5.1.1 "><p id="smn_api_54002__p438298719494">project_id</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="19.28%" headers="mcps1.3.2.3.1.1.1.5.1.2 "><p id="smn_api_54002__p1947768019494">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.3.2.3.1.1.1.5.1.3 "><p id="smn_api_54002__p3418823319494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="38.550000000000004%" headers="mcps1.3.2.3.1.1.1.5.1.4 "><p id="smn_api_54002__p26342752155347">Project ID</p>
|
|
<p id="smn_api_54002__p1778348719494">See <a href="smn_api_66000.html">Obtaining a Project ID</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="smn_api_54002__row1215136319494"><td class="cellrowborder" valign="top" width="20.48%" headers="mcps1.3.2.3.1.1.1.5.1.1 "><p id="smn_api_54002__p4473635119494">topic_urn</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="19.28%" headers="mcps1.3.2.3.1.1.1.5.1.2 "><p id="smn_api_54002__p6687467519494">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.3.2.3.1.1.1.5.1.3 "><p id="smn_api_54002__p4813962419494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="38.550000000000004%" headers="mcps1.3.2.3.1.1.1.5.1.4 "><p id="smn_api_54002__p699549419494">Unique resource ID of the topic. You can obtain it by referring to <a href="en-us_topic_0036016755.html">Querying Topics</a>.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="smn_api_54002__section6208316219494"><h4 class="sectiontitle">Request</h4><ul id="smn_api_54002__ul6268022519494"><li id="smn_api_54002__li2725111619494">Parameter description
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="smn_api_54002__table4393345619494" frame="border" border="1" rules="all"><thead align="left"><tr id="smn_api_54002__row5198822719494"><th align="left" class="cellrowborder" valign="top" width="19.18808119188081%" id="mcps1.3.3.2.1.1.1.5.1.1"><p id="smn_api_54002__p5029685319494"><strong id="smn_api_54002__b1382246778">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="18.64813518648135%" id="mcps1.3.3.2.1.1.1.5.1.2"><p id="smn_api_54002__p4751327919494"><strong id="smn_api_54002__b6259598993519">Mandatory</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="21.40785921407859%" id="mcps1.3.3.2.1.1.1.5.1.3"><p id="smn_api_54002__p2337041019494"><strong id="smn_api_54002__b1211940485">Type</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="40.75592440755925%" id="mcps1.3.3.2.1.1.1.5.1.4"><p id="smn_api_54002__p1395507019494"><strong id="smn_api_54002__b1119357231">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="smn_api_54002__row2272409419494"><td class="cellrowborder" valign="top" width="19.18808119188081%" headers="mcps1.3.3.2.1.1.1.5.1.1 "><p id="smn_api_54002__p2871231519494">subject</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.64813518648135%" headers="mcps1.3.3.2.1.1.1.5.1.2 "><p id="smn_api_54002__p4399616019494">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.40785921407859%" headers="mcps1.3.3.2.1.1.1.5.1.3 "><p id="smn_api_54002__p691922219494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40.75592440755925%" headers="mcps1.3.3.2.1.1.1.5.1.4 "><p id="smn_api_54002__p2358611619494">Message subject, which is presented as the email subject when SMN sends messages to email subscribers</p>
|
|
<p id="smn_api_54002__p950615309415">The message subject cannot exceed 512 bytes.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="smn_api_54002__row1441009919494"><td class="cellrowborder" valign="top" width="19.18808119188081%" headers="mcps1.3.3.2.1.1.1.5.1.1 "><p id="smn_api_54002__p2636733319494">message_structure</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.64813518648135%" headers="mcps1.3.3.2.1.1.1.5.1.2 "><p id="smn_api_54002__p5537924419494">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.40785921407859%" headers="mcps1.3.3.2.1.1.1.5.1.3 "><p id="smn_api_54002__p5653380819494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40.75592440755925%" headers="mcps1.3.3.2.1.1.1.5.1.4 "><p id="smn_api_54002__p5266151611219">Message structure, which contains JSON strings</p>
|
|
<p id="smn_api_54002__p16881184062217"><strong id="smn_api_54002__b842352706184247">email</strong>, <strong id="smn_api_54002__b842352706184251">sms</strong>, <strong id="smn_api_54002__b842352706184256">http</strong>, and <strong id="smn_api_54002__b84235270618430">https</strong> are supported.</p>
|
|
<p id="smn_api_54002__p1583573619494">The <strong id="smn_api_54002__b84235270693914">default</strong> protocol is mandatory. If the system fails to match any other protocols, the default message is sent.</p>
|
|
<div class="note" id="smn_api_54002__note1920913487410"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="smn_api_54002__p2142739193425">Three message formats are supported:</p>
|
|
<ul id="smn_api_54002__ul39581890193437"><li id="smn_api_54002__li59236208193437">message</li><li id="smn_api_54002__li11736077193441">message_structure</li><li id="smn_api_54002__li31130716193457">message_template_name</li></ul>
|
|
<p id="smn_api_54002__p38575679193513">If the three formats are specified at the same time, they take effect in the following sequence: <strong id="smn_api_54002__b842352706142832">message_structure</strong> > <strong id="smn_api_54002__b842352706142838">message_template_name</strong> > <strong id="smn_api_54002__b842352706142846">message</strong>.</p>
|
|
</div></div>
|
|
</td>
|
|
</tr>
|
|
<tr id="smn_api_54002__row6307720141310"><td class="cellrowborder" valign="top" width="19.18808119188081%" headers="mcps1.3.3.2.1.1.1.5.1.1 "><p id="smn_api_54002__p23681125515">time_to_live</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.64813518648135%" headers="mcps1.3.3.2.1.1.1.5.1.2 "><p id="smn_api_54002__p23681626518">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="21.40785921407859%" headers="mcps1.3.3.2.1.1.1.5.1.3 "><p id="smn_api_54002__p18075392520">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="40.75592440755925%" headers="mcps1.3.3.2.1.1.1.5.1.4 "><p id="smn_api_54002__p1446072420515">The maximum retention period of a message in SMN</p>
|
|
<p id="smn_api_54002__p10113839148">After the retention period expires, SMN does not send this message.</p>
|
|
<p id="smn_api_54002__p237518351441">Unit: second</p>
|
|
<p id="smn_api_54002__p66191571978">Default retention period: <strong id="smn_api_54002__b84235270617311">3600</strong> (one hour)</p>
|
|
<p id="smn_api_54002__p185211212174217">The retention period must be a positive integer less than or equal to 604,800 (3600 x 24 x 7).</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li><li id="smn_api_54002__li152741519494">Example request<pre class="screen" id="smn_api_54002__screen17172411105310">POST https://{SMN_Endpoint}/v2/{project_id}/notifications/topics/urn:smn:regionId: f96188c7ccaf4ffba0c9aa149ab2bd57:test_create_topic_v2/publish</pre>
|
|
<pre class="screen" id="smn_api_54002__screen50464696194927">{
|
|
"subject": "test message v2",
|
|
"time_to_live": "3600",
|
|
"message_structure": "{\n \"default\": \"xxx\",\n \"APNS\": \"{\\\"aps\\\":{\\\"alert\\\":{\\\"title\\\":\\\"xxx\\\",\\\"body\\\":\\\"xxx\\\"}}}\"\n}"
|
|
}</pre>
|
|
<div class="note" id="smn_api_54002__note31878112173834"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="smn_api_54002__p47737238173837">For example, a topic has two types of subscriptions, SMS and email. After the API is called to publish messages, the email subscriber will receive message "abc", and the SMS subscriber will receive the default message "test v2 default". </p>
|
|
</div></div>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="smn_api_54002__section6514890019494"><h4 class="sectiontitle">Response</h4><ul id="smn_api_54002__ul4256954419494"><li id="smn_api_54002__li4758158319494">Parameter description
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="smn_api_54002__table2558106919494" frame="border" border="1" rules="all"><thead align="left"><tr id="smn_api_54002__row4596945119494"><th align="left" class="cellrowborder" valign="top" width="31.756824317568245%" id="mcps1.3.4.2.1.1.1.4.1.1"><p id="smn_api_54002__p3253804119494"><strong id="smn_api_54002__b1979741992">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="32.736726327367265%" id="mcps1.3.4.2.1.1.1.4.1.2"><p id="smn_api_54002__p1833566819494"><strong id="smn_api_54002__b1659428811">Type</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="35.5064493550645%" id="mcps1.3.4.2.1.1.1.4.1.3"><p id="smn_api_54002__p879411519494"><strong id="smn_api_54002__b1504753416">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="smn_api_54002__row5167660719494"><td class="cellrowborder" valign="top" width="31.756824317568245%" headers="mcps1.3.4.2.1.1.1.4.1.1 "><p id="smn_api_54002__p2505561119494">request_id</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="32.736726327367265%" headers="mcps1.3.4.2.1.1.1.4.1.2 "><p id="smn_api_54002__p1623863619494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.5064493550645%" headers="mcps1.3.4.2.1.1.1.4.1.3 "><p id="smn_api_54002__p4026117819494">Request ID, which is unique</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="smn_api_54002__row2382565119494"><td class="cellrowborder" valign="top" width="31.756824317568245%" headers="mcps1.3.4.2.1.1.1.4.1.1 "><p id="smn_api_54002__p5082954219494">message_id</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="32.736726327367265%" headers="mcps1.3.4.2.1.1.1.4.1.2 "><p id="smn_api_54002__p2355227519494">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="35.5064493550645%" headers="mcps1.3.4.2.1.1.1.4.1.3 "><p id="smn_api_54002__p2868611219494">Message ID, which is unique</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li><li id="smn_api_54002__li4131913919494">Example response<pre class="screen" id="smn_api_54002__screen48301616194940">{
|
|
"message_id": "bf94b63a5dfb475994d3ac34664e24f2",
|
|
"request_id": "9974c07f6d554a6d827956acbeb4be5f"
|
|
}</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="smn_api_54002__section585587219494"><h4 class="sectiontitle">Returned Value</h4><p id="smn_api_54002__p456360819494">See <a href="smn_api_63002.html">Returned Value</a>.</p>
|
|
</div>
|
|
<div class="section" id="smn_api_54002__section73211020122511"><h4 class="sectiontitle">Error Codes</h4><p id="smn_api_54002__p9759142919265">See <a href="smn_api_64000.html">Error Codes</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="smn_api_54000.html">Message Publishing</a></div>
|
|
</div>
|
|
</div>
|
|
|