Home > Mobile >  whatsapp cloud api template object issue to send from postman
whatsapp cloud api template object issue to send from postman

Time:12-01

enter image description hereI'm trying to send the whatsapp cloud template from postman. I created a template in whatsapp cloud with header media image, body content,footer and two buttons.

the response of the templates when i use get api is as below

        {
        "name": "trns_btn_img_header_XXX",
        "components": [
            {
                "type": "HEADER",
                "format": "IMAGE",
                "example": {
                    "header_handle": [
                        "https://img.url.com"
                    ]
                }
            },
            {
                "type": "BODY",
                "text": "Body message"
            },
            {
                "type": "FOOTER",
                "text": "ftr optioal"
            },
            {
                "type": "BUTTONS",
                "buttons": [
                    {
                        "type": "QUICK_REPLY",
                        "text": "qrbtnone"
                    },
                    {
                        "type": "QUICK_REPLY",
                        "text": "qrbtntwo"
                    }
                ]
            }
        ],
        "language": "en_US",
        "status": "APPROVED",
        "category": "TRANSACTIONAL",
        "id": "17XX209448XXXXXX"
    }

I tried the template json object in postman is as below

{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "{{message_to}}",
    "type": "template",
  "template": {
    "name": "trns_btn_img_header_XXX",
    "language": {
      "code": "en_US"
    },
    "components": [
      {
        "type": "header",
        "parameters": [
          {
            "type": "image",
            "image": {
              "link": "https://img.jpg.com"
            }
          }
        ]
      },
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Body message from pm"
          },         
        ]
      },
      {
        "type": "footer",
        "parameters": [
          {
            "type": "text",
            "text": "footer message from pm"
          },         
        ]
      },
      {
        "type": "button",
        "sub_type": "quick_reply",
        "index": "0",
        "parameters": [
          {
            "type": "text",
            "text": "btnone"
          }
        ]
      },
      {
        "type": "button",
        "sub_type": "quick_reply",
        "index": "1",
        "parameters": [
          {
            "type": "text",
            "text": "btntwo"
          }
        ]
      }
    ]
  }
}

the response error is "error": { "message": "(#132000) Number of parameters does not match the expected number of params"

CodePudding user response:

Make sure and correct the below things in send message endpoint request,

  • Don't need to pass body component if there are no parameters in the body text, if there are parameters then you need to pass only that parameters text in the separate object of parameters in index order
  • Don't need to pass the footer component because it is static when you create a template
  • the quick_reply button type, use type as "payload" instead of "text" in parameters
    {
       "type": "button",
       "sub_type": "quick_reply",
       "index": "1",
       "parameters": [
         {
           "type": "payload",
           "payload": "btntwo"
         }
       ]
     }
    

CodePudding user response:

Below object worked for me

{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "{{message_to}}",
    "type": "template",
  "template": {
    "name": "trns_btn_img_header_XXX",
    "language": {
      "code": "en_US"
    },
    "components": [
      {
        "type": "header",
        "parameters": [
          {
            "type": "image",
            "image": {
              "link": "https://www.w3schools.com/html/pic_trulli.jpg"
            }
          }
        ]
      },
      {
        "type": "button",
        "sub_type": "quick_reply",
        "index": "0",
        "parameters": [
          {
            "type": "payload",
            "payload": "btntwo"
          }
        ]
      },
      {
        "type": "button",
        "sub_type": "quick_reply",
        "index": "1",
        "parameters": [
          {
            "type": "payload",
            "payload": "btnto"
          }
        ]
      }
    ]
  }
}
  • Related