简体   繁体   English

从 CURL 示例实现 Twilio Api 调用 js 返回状态码 200 但似乎没有更新数据

[英]Implementing Twilio Api call from a CURL example to js returns status code of 200 but does not seem to update data

I am trying to update my sim fleet name and sim unique name without any success我正在尝试更新我的 sim 机队名称和 sim 唯一名称但没有成功

  const url = `https://supersim.twilio.com/v1/Sims/${sid}? fleet=${fleet}&uniqueName=${uniqueName}`;


  const resp = await fetch(url, {
    method: "POST",
    headers: new Headers({
      Authorization: auth.twilioAuth,
      "Content-Type": "application/x-www-form-urlencoded",
    }),
    body: new URLSearchParams({
      Iccid: iccid,
    }).toString(),
  });

I get a 200 response with my sim object as follows我的 sim 卡 object 收到 200 响应,如下所示

account_sid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
date_created: "2022-01-08T21:05:00Z"
date_updated: "2022-01-08T21:05:00Z"
fleet_sid: null  //did not update
iccid: "XXXXXXXXXXXXX"
links: {billing_periods: 'https://supersim.twilio.com/v1/Sims/HSXXXXXXXXXXXXXXXXXXXXXXXX/BillingPeriods'}
sid: "HSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
status: "new"
unique_name: null  //did not update
url: "https://supersim.twilio.com/v1/Sims/HSXXXXXXXXXXXXXXXXXXXXXXXXXXX"


Twilio documentation Twilio 文档

and this is what their CURL example website says这就是他们的 CURL 示例网站所说的

curl -X POST https://wireless.twilio.com/v1/Sims/DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--data-urlencode "CallbackMethod=POST" \
--data-urlencode "CallbackUrl=https://sim-manager.mycompany.com/sim-update-callback/AliceSmithSmartMeter" \
--data-urlencode "Status=active" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

You should send the parameters you want to update in the body of the request, not in the query parameters.您应该在请求正文中发送要更新的参数,而不是在查询参数中。 Also note that the parameter names are in Pascal case .另请注意, 参数名称采用Pascal 大小写 Try this:尝试这个:

  const url = `https://supersim.twilio.com/v1/Sims/${sid}`;

  const resp = await fetch(url, {
    method: "POST",
    headers: new Headers({
      Authorization: auth.twilioAuth,
      "Content-Type": "application/x-www-form-urlencoded",
    }),
    body: new URLSearchParams({
      Iccid: iccid,
      Fleet: fleet,
      UniqueName: uniqueName
    }).toString(),
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM