Home > Software design >  Sending media parameter is not working while sending it to kaleyra api through code
Sending media parameter is not working while sending it to kaleyra api through code

Time:06-05

https://developers.kaleyra.io/docs/send-a-media-template-message-through-whatsapp

I am trying to send a media to kalerays api through my code. But it is not working when I pass from code. But When I hit the API from postman then it works fine.

async whatsappAPIWithAttachment(requestBody) {
     let api_key = "";
    if (requestBody.campaign) {
      api_key = "x";
    } else {
      api_key = "Y";
    }
    
    var data = qs.stringify({
      from: "xyz",
      to: "xyz",
      type: "mediatemplate",
      channel: "whatsapp",
      template_name: "xyz",
      params: '"name","vendor"',
      lang_code: "en",
      media_url: "http://www.africau.edu/images/default/sample.pdf",
    });

    var config: AxiosRequestConfig = {
      method: "post",
      url: "https://api.kaleyra.io/v1/HXIN1707222213IN/messages",
      headers: {
        "api-key": api_key,
        "content-type": "multipart/form-data",
      },
      data: data,
    };

    let response = await axios(config);
    return response.data;
  }
}

It gives me an enter image description hereerror request failed with status code 400. Here I have replaced X, Y, and XYZ with actual parameters. So Inputs are correct but still get an error saying 'E413', message: 'Invalid/incorrect inputs.

CodePudding user response:

As per sample request in kaleyra documentation, they have used

--header 'Content-Type: application/json'

while you are passing

"content-type": "multipart/form-data",

pls correct it and try.

CodePudding user response:

how about using double quote strings for param value

params: "\"name\",\"vendor\""
  • Related