# Content Template APIs

# Create Template

Method: POST
Path: /content-template/api/projects//templates
Description: Create a new template, require client scope as below.

Client Scope:
- template.w

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Body:

Param Description Type Required
ref Reference name that specific each templates. String Y
name Name of template. String N
body Message of template. String Y

Request Body Example:

{
  "ref": "sms_order_open",
  "name": "order_open",
  "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
}

Request Example:

curl -X POST \
--header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' -d '{ \ 
 	 { \ 
          "ref": "sms_order_open",
          "name": "order_open",
          "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
     } \ 
 }' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/templates'

Response Example:

HTTP/1.1 201 CREATED
Content-Type: application/json
{
    "id": "5f59d8a03b0c013c5972adfc",
    "projectId": "5f5082f55c4cd100010ddcc3",
    "ref": "sms_order_open",
    "name": "order_open",
    "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
}

# Update Template

Method: PUT
Path: /content-template/api/projects//templates
Description: Update a new template, require client scope as below.

Client Scope:
- template.w

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Body:

Param Description Type Required
id Reference Id of template. String Y
ref Reference name that specific each templates. String Y
name Name of template. String N
body Message of template. String Y

Request Body Example:

{
    "id": "5f59d8a03b0c013c5972adfc",
    "ref": "sms_order_booked",
    "name": "order_open_booked",
    "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
}

Request Example:

curl -X PUT \
--header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' -d '{ \ 
 	 { \ 
            "id": "5f59d8a03b0c013c5972adfc",
            "ref": "sms_order_booked",
            "name": "order_open_booked",
            "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
     } \ 
 }' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/templates'

Response Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
    "id": "5f59d8a03b0c013c5972adfc",
    "ref": "sms_order_booked",
    "name": "order_open_booked",
    "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
}

# Get template

Method: GET
Path: /content-template/api/projects//templates/{id}
Description: Get template by templateId, require client scope as below.

Client Scope:
- template.r

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Example:

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/templates/5f509384857fe64f0f36735c'

Response Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
    "id": "5f59d8a03b0c013c5972adfc",
    "projectId": "5f5082f55c4cd100010ddcc3",
    "ref": "sms_order_booked",
    "name": "order_open_booked",
    "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
}

# Get all template

Method: GET
Path: /content-template/api/projects//templates
Description: Get all template of project, require client scope as below.

Client Scope:
- template.r

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Example:

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/templates'

Response Example:

HTTP/1.1 200 OK
Content-Type: application/json
[
    {
        "id": "5f509384857fe64f0f36735c",
        "projectId": "5f5082f55c4cd100010ddcc3",
        "ref": "sms_order",
        "name": "sms_order_check",
        "body": "<#list data as record> ${record.senderName} พัสดุหมายเลข ${record.orderTrackingNumber} ของรายการสั่งซื้อ ${record.orderNumber} อยู่ในระหว่างการจัดส่ง คุณสามารถตรวจสอบสถานะการจัดส่งได้ที่เว็บของเรา <#list record.items as item>${item}\n</#list> </#list>"
    },
    {
        "id": "5f59d8a03b0c013c5972adfc",
        "projectId": "5f5082f55c4cd100010ddcc3",
        "ref": "sms_order_booked",
        "name": "order_open_booked",
        "body": "${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว"
    }
]

# Delete template

Method: DELETE
Path: /content-template/api/projects//templates/{id}
Description: Delete template by templateId, require client scope as below.

Client Scope:
- template.w

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Example:

curl -X DELETE --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/templates/5f509384857fe64f0f36735c'

Response Example:

HTTP/1.1 204 No Content
Content-Type: application/json

# Resolve Template

Method: POST
Path: /content-template/api/projects//template-resolve
Description: Resolve a template, require client scope as below.

Client Scope:
- template.r

Authority: -

Request Header:

Param Description Required Example
Authorization The OAuth2 authentication with the O2O System Y Bearer {O2O Access Token}
Content-Type The MIME type of this content Y application/json

Request Body:

Param Description Type Required
templateRef Reference name that specific each templates. String Y
values Values that resolve on template. String N

Request Body Example:

{
    "templateRef": "sms_order_booked",
    "values": {
        "senderName" : "trueBiz",
        "ali": {
            "orderNo": "DO-NK8KA54GXE",
            "refNo": "MCDEVLIERY-006",
            "trackingNo": "855415222532313088",
            "currentStatus": "PICKING",
            "logisticsLogo": "https://www.lalamove.com/hs-fs/hubfs/Design/logo/logo_width200-01-1.png?width=200&name=logo_width200-01-1.png",
            "logisticsName": "Lalamove",
            "logisticsCompanySid": "LALAMOVE",
            "history": [
                {
                    "status": "PENDING",
                    "message": "waiting for logistics to pick up",
                    "createdAt": "2020-04-16T03:54:43+07",
                    "driverName": "Peam Pummarin",
                    "driverPhone": "0874992880",
                    "driverPlateNumber": "xxx"
                }
            ]
        }
    }
}

Request Example:

curl -X POST \
--header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer {O2O Access Token}' -d '{ \ 
 	 {
         "templateRef": "sms_order_booked",
         "values": {
             "senderName" : "trueBiz",
             "ali": {
                 "orderNo": "DO-NK8KA54GXE",
                 "refNo": "MCDEVLIERY-006",
                 "trackingNo": "855415222532313088",
                 "currentStatus": "PICKING",
                 "logisticsLogo": "https://www.lalamove.com/hs-fs/hubfs/Design/logo/logo_width200-01-1.png?width=200&name=logo_width200-01-1.png",
                 "logisticsName": "Lalamove",
                 "logisticsCompanySid": "LALAMOVE",
                 "history": [
                     {
                         "status": "PENDING",
                         "message": "waiting for logistics to pick up",
                         "createdAt": "2020-04-16T03:54:43+07",
                         "driverName": "Peam Pummarin",
                         "driverPhone": "0874992880",
                         "driverPlateNumber": "xxx"
                     },
                     {
                         "status": "PENDING",
                         "message": "waiting for logistics to pick up",
                         "createdAt": "2020-04-16T03:54:43+07",
                         "driverName": "Por Pummarin",
                         "driverPhone": "0874992889",
                         "driverPlateNumber": "xxx"
                     }
                 ]
             }
         }
     }
 }' 'https://dev-platform.weomni-test.com/content-template/api/projects/5f5082f55c4cd100010ddcc3/template-resolve'

Template Example:

    ${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว

Response Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
    "templateRef": "sms_order_booked",
    "message": "trueBiz คุณได้ทำรายการสั่งซื้อ DO-NK8KA54GXE เรียบร้อยแล้ว"
}

Response UnResolve Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
    "entityName": "contenttemplateTemplate",
    "errorKey": "invalidProjectIdOrRef",
    "type": "https://www.jhipster.tech/problem/problem-with-message",
    "title": "Invalid projectId or refTemplate of template in project 5f5082f55c4cd100010ddcc3",
    "status": 400,
    "message": "error.invalidProjectIdOrRef",
    "params": "contenttemplateTemplate"
}

Sequence Operator
Template api can loop of items with syntax :

    <#list ${datas} as data>
         ${data}
    </#list>

${datas} : all items that need to loop
data : name to reference inside loop


Sequence Template Example:

    ${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว <#list ali.history as h> จัดส่งโดย ${h.driverName} สถานะ ${h.status} </#list>

Sequence Template Example:

     ${senderName} คุณได้ทำรายการสั่งซื้อ ${ali.orderNo} เรียบร้อยแล้ว
     <#list ali.history as h> 
         จัดส่งโดย ${h.driverName} สถานะ ${h.status} 
     </#list>

Response Sequence Template Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
    "templateRef": "test_loop",
    "message": "fame คุณได้ทำรายการสั่งซื้อ DO-NK8KA54GXE เรียบร้อยแล้ว  จัดส่งโดย Peam Pummarin สถานะ PENDING  จัดส่งโดย Por Pummarin สถานะ PENDING "
}

See more detail: https://freemarker.apache.org/docs/dgui_template_exp.html

Last Updated: 9/14/2020, 3:38:45 AM