Whatsapp API (#132000) Number of parameters does not match the expected number of params - api

I created below template in Whatsapp API. And I want to set the parameter value in the API call. What is the correct payload ? I have been following the Meta docs and trying but everytime I get error. Please Help.
Template:
You order # {{1}} is received successfully.
I used this payload:
{
"messaging_product": "whatsapp",
"to": "918456712349",
"type": "template",
"template": {
"name": "order_notification",
"language": {
"code": "en_US"
}
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "135345345"
}
]
}
]
}
But I am still getting this error
{
"error": {
"message": "(#132000) Number of parameters does not match the expected number of params",
"type": "OAuthException",
"code": 132000,
"error_data": {
"messaging_product": "whatsapp",
"details": "body: number of localizable_params (0) does not match the expected number of params (1)"
},
"error_subcode": 2494002,
"fbtrace_id": "AzPa-uWXctIcdNVu0Lf3Fic"
}
}

The issue due to closing the template object then opening a new component object.
make the component object inside the template object and it will be fixed
{
"messaging_product": "whatsapp",
"to": "918456712349",
"type": "template",
"template": {
"name": "order_notification",
"language": {
"code": "en_US"
}
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "135345345"
}
]
}
]
}
}

change in parameter type "header", this code run for me:
{
"messaging_product": "whatsapp",
"to": "918456712349",
"type": "template",
"template": {
"name": "order_notification",
"language": {
"code": "en_US"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "xxxxxxx"
}
]
}
]
}
}

Looks like the template is expecting 1 parameter, which is not being provided.
You can look at the documentation and example here.
It includes a working example.

Related

Unable to retrieve data from catalog using WhatsApp Cloud API

I'm unable to send multiproduct messages to users. Every time I send the request I receive the same error. The following attachment shows the catalog connected to the number.
The body of the request:
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "###########",
"type": "interactive",
"interactive": {
"type": "product_list",
"header": {
"type": "text",
"text": "text-header-content"
},
"body": {
"text": "text-body-content"
},
"footer": {
"text": "text-footer-content"
},
"action": {
"catalog_id": "673529427462715",
"sections": [
{
"title": "the-section-title",
"product_items": [
{
"product_retailer_id": "K456653445"
}
]
}
]
}
}
}
The error received:
{
"error": {
"message": "(#131009) Parameter value is not valid",
"type": "OAuthException",
"code": 131009,
"error_data": {
"messaging_product": "whatsapp",
"details": "None of the products provided could be sent. Please check your catalog."
},
"error_subcode": 2494010,
"fbtrace_id": "A4YbEq8SQ7rMIisuc4M2HiX"
}
}

Sample code for WhatsApp interactive template message

Does anyone have a sample code for WhatsApp interactive template message?
I am trying to trigger an API from postman but getting the below error:
{
"meta": {
"api_status": "stable",
"version": "2.37.1"
},
"errors": [
{
"code": 2012,
"title": "Parameter format does not match format in the created template",
"details": "header: Format mismatch, expected Video, received Unknown",
"href": "https://developers.facebook.com/docs/whatsapp/faq#faq_1612022582274564"
}
]
}
Here is what I added in the body:
{
"to": "91NUMBER",
"type": "template",
"template": {
"namespace": "NAMESPACE_ID",
"language": {
"policy": "deterministic",
"code": "en"
},
"name": "TEMPLATE_NAME",
"components": [
{
"type": "header",
"parameters": [
{
"type": "video",
"video": {
"link": "https://res.cloudinary.com/MY_VIDEO_LINK"
}
}
],
"type": "button",
"sub_type": "url",
"index": "0",
"parameters": [
{
"type": "text",
"text": "9rwnB8RbYmPF5t2Mn09x4h"
}
]
}
]
}
}
Any sort of help would be appreciated.
PS: I'm still new to this.
Use the below code maybe it works
{
"to": "91NUMBER",
"type": "template",
"template": {
"namespace": "NAMESPACE_ID",
"language": {
"policy": "deterministic",
"code": "en"
},
"name": "TEMPLATE_NAME",
"components": [
{
"type": "header",
"parameters": [
{
"type": "video",
"video": {
"link": "https://res.cloudinary.com/MY_VIDEO_LINK"
}
}
]
},
{
"type": "button",
"sub_type": "url",
"index": "0",
"parameters": [
{
"type": "text",
"text": "9rwnB8RbYmPF5t2Mn09x4h"
}
]
}
]
}
}

OpenAPI Example multipart form data

I have a multipart/form-data POST in an API endpoint which takes some key/value strings, and a file upload via the key files.
I believe I have defined it correctly in OpenAPI;
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"file": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
}
},
"myKey1": {
"type": "string"
},
"myKey2": {
"type": "string"
}
}
},
"examples": {
"value": ?
}
}
}
},
However, I am unsure how I can describe an example for a multipart/form-data in the examples field.
I assume I don't need to represent the file (although that would be a bonus) but just the myKey1 and myKey2 keys and values.
Your OAS definition seems to be correct. You can define the examples as shown below:
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"file": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
},
"example": [
{
"externalValue": "http://www.africau.edu/images/default/sample.pdf"
}
]
},
"myKey1": {
"type": "string",
"example": "myKey1Example"
},
"myKey2": {
"type": "string",
"example": "myKey2Example"
}
}
}
}
}
},
externalValue can be added to point the sample file URL in Open API Specification. This is only for the document purpose.
However, it will not be displayed in the swagger-ui as swagger-ui does not support it yet. It is tracked in [1].
[1] https://github.com/swagger-api/swagger-ui/issues/5433

Deploying template using PowerShell script failed

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "eNtsaBuilding M103",
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"MandelaUniversity2019": "[concat(uniquestring(resourceGroup().id), 'standardsa')]"
},
"resources": [
{
"type": "Microsoft.Storage/eNtsaResourcesIOT",
"name": "[variables('MandelaUniversity2019')]",
"apiVersion": "2018-01-06",
"location": "[resourceGroup().location]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "Storage",
"properties": {
}
}
],
"outputs": {
"MandelaUniversity2019": {
"type": "string",
"value": "[variables('MandelaUniversity2019')]"
}
}
}
14:16:57 - 2:16:56 PM - Resource Microsoft.Storage/eNtsaResourcesIOT 'fi7so6zmvqa2istandardsa' failed with message '{
14:16:57 - "error": {
14:16:57 - "code": "InvalidResourceType",
14:16:57 - "message": "The resource type could not be found in the namespace 'Microsoft.Storage' for api version '2018-01-06'."
14:16:57 - }
14:16:57 - }'
How do i solve this problem, i am trying to create a template using VS 2019 and my deploymentJSON script indicate that error. Please assist as i dont know Yes invalidResourceType but i do have that Resource type on my portal. Is there anything should add or modify on this JSON script? Please guide me to resolve this issue, thanks.
As mentioned in the comments, use this:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "eNtsaBuilding M103",
"metadata": {
"description": "Storage Account type"
}
}
},
"variables": {
"MandelaUniversity2019": "[concat(uniquestring(resourceGroup().id), 'standardsa')]"
},
"resources":[
{
"type":"Microsoft.Storage/storageAccounts",
"name":"[variables('storageAccountName')]",
"apiVersion":"2018-07-01",
"location":"eastus",
"sku":{
"name":"Standard_LRS",
"tier":"Standard"
},
"kind":"Storage",
"properties":{
}
}
],
"outputs": {
"MandelaUniversity2019": {
"type": "string",
"value": "[variables('MandelaUniversity2019')]"
}
}
}

Json property structure dependant of another property

I've been working on a json schema to validate the answers from one of my webservices.
The answer is splitted in two properties: data and status. If status.code is set to 0, then data will have to respect a specific schema. Else, if status.code is set to -1, data won't be read, so I don't want to check if it respects the schema.
Here is the schema :
{
"$schema": "http://json-schema.org/schema#",
"id": "file://registration.json",
"type": "object",
"properties": {
"status": {
"$ref": "#/definitions/classes/status"
}
},
"anyOf": [
{
"$ref": "#/definitions/conditions/status-is-ok"
},
{
"$ref": "#/definitions/conditions/status-is-nok"
}
],
"definitions": {
"classes": {
"status": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
},
"data": {
"type": "object",
"properties": {
"propertyA": {
"type": "#/definitions/classes/metadatauser"
},
"propertyB": {
"type": "#/definitions/classes/membreinfo"
}
},
"required": ["propertyA", "propertyB"]
}
},
"conditions": {
"status-is-ok": {
"status": {
"properties": {
"code": 0
}
},
"data": {
"$ref": "#/definitions/classes/data"
}
},
"status-is-nok": {
"status": {
"properties": {
"code": -1
}
},
"data": {
"type": "object"
}
}
}
}
}
And here's an example of what should not be validated:
{
"data": {},
"status": {
"code": 0,
"message": "OK"
}
}
At the moment, this portion of code passes, and I don't know why.
You've got a few things wrong here, so I'll try to explain all of them. You were on the right track!
"properties": {
"code": 0
}
The value of "properties" MUST be an object. Each value of this object
MUST be a valid JSON Schema.
http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.5.4
You can't put the value you expect as the value for a property key.
You CAN however use the [const]1 keyword to achive a specific value validation.
"$ref": "#/definitions/conditions/status-is-ok"
...
"conditions": {
"status-is-ok": {
"status": {
"properties": {
[The definitions] keyword's value MUST be an object. Each member value of this
object MUST be a valid JSON Schema.
https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-9
This means that you need to treat each value of each key in a defintions as a JSON Schema. If you had a JSON Schema where you did not nest "status" inside a properties object, no validation would take place. The same is true for "data".
(Strictly, according to the definitions section of the spec, you MUST NOT nest schemas deeply in the definitions object, but this seems to be supported by some implementations anyway, and resolves using the correct resolution rules. Prefixing may be better.)
The complete fixed schema is as follows.
{
"$schema": "http://json-schema.org/schema#",
"id": "file://registration.json",
"type": "object",
"properties": {
"status": {
"$ref": "#/definitions/classes/status"
}
},
"anyOf": [
{
"$ref": "#/definitions/conditions/status-is-ok"
},
{
"$ref": "#/definitions/conditions/status-is-nok"
}
],
"definitions": {
"classes": {
"status": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
},
"data": {
"type": "object",
"properties": {
},
"required": [
"propertyA",
"propertyB"
]
}
},
"conditions": {
"status-is-ok": {
"properties": {
"status": {
"properties": {
"code": {
"const": 0
}
}
},
"data": {
"$ref": "#/definitions/classes/data"
},
},
"additionalProperties": false
},
"status-is-nok": {
"properties": {
"status": {
"properties": {
"code": {
"const": -1
}
}
},
"data": {
"type": "object"
},
},
"additionalProperties": false
}
}
}
}
Please do let me know if any of this doesn't make sense.
Feel free to join the JSON Schema slack server should you want to discuss any aspects further! Happy to also comment here.