drnxnbf199049 2018-03-12 17:25 采纳率: 100%
浏览 270

PHP CURL PATCH到API创建而不是更新

I am using a client management software called UCRM. The API I am using is meant to patch/update but it seems to make new entries when it comes to the contacts array.

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, "http://url.com" . $clientID);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_HEADER, FALSE);

            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");

            curl_setopt($ch, CURLOPT_POSTFIELDS, "{
              \"contacts\": [
                {
                  \"phone\": \"" . $pendingTo . "\"
                }
              ]
            }");

            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
              "Content-Type: application/json",
              "X-Auth-App-Key: 12345"
            ));

            $response = curl_exec($ch);
            curl_close($ch);

I can't figure out how to make it update the existing phone number in the contacts array. The code above seems to add to the array.

  • 写回答

1条回答 默认 最新

  • doubi8965 2018-03-13 13:56
    关注

    Take a look at the UCRM API Inspector.

    Apparently, your request is invalid because "street1", "city" and "zipCode" are required:

    At '/street1' Missing required property: street1

    At '/city' Missing required property: city

    At '/zipCode' Missing required property: zipCode

    Try it like this and let me know:

    {
    
      "street1": "2580 Orchard Pkwy",
    
      "city": "San Jose",
    
      "zipCode": "95131",
    
      "contacts": [
    
        {
    
          "phone": "1234"
    
        }
    
      ]
    
    }
    

    I would actually advise you to run a GET first on the customer you want to update, modify the JSON string that is returned and then PATCH it.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。