簡體   English   中英

通過代碼將媒體參數發送到kaleyra api時發送媒體參數不起作用

[英]Sending media parameter is not working while sending it to kaleyra api through code

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

我正在嘗試通過我的代碼將媒體發送到 kalerays api。 但是當我從代碼傳遞時它不起作用。 但是當我從郵遞員那里點擊 API 時,它就可以正常工作了。

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;
  }
}

它給了我一個輸入圖像描述here error request failed with status code 400。這里我用實際參數替換了X、Y和XYZ。 所以輸入是正確的,但仍然收到錯誤消息“E413”,消息:“輸入無效/不正確。

根據 kaleyra 文檔中的示例請求,他們使用了

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

當你經過時

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

請糾正並嘗試。

如何使用雙引號字符串作為參數值

params: "\"name\",\"vendor\""

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM