twilio / twilio-php

A PHP library for communicating with the Twilio REST API and generating TwiML.
MIT License
1.57k stars 562 forks source link

Unset a property while updating #711

Closed oprypkhantc closed 2 years ago

oprypkhantc commented 2 years ago

Issue Summary

Given a created entity with a non-null optional property, there seems to be no way to update the property to be null. It gets encoded as an empty string and Twilio API doesn't unset the value. Returned entity still contains the previously set property value.

Steps to Reproduce

  1. Create an entity with an optional parameter filled
  2. Attempt to update it, passing null as parameter's value

Code Snippet

$conversation = $client->conversations->conversations->create(['friendlyName' => 'test']);
$conversation = $conversation->update(['friendlyName' => null]);

// Fails!
assert($conversation->friendlyName === null);
POST https://conversations.twilio.com/v1/Services/IS11111111ac44e5e9b52c2b010f8ea3a/Conversations/threads_2259
Authorization: Basic ****
Accept-Charset: utf-8
Content-Type: application/x-www-form-urlencoded
Accept: application/json

FriendlyName=

results in

{
    "unique_name": "threads_2259",
    "date_updated": "2021-12-07T18:00:34Z",
    "friendly_name": "test",
    "timers": {},
    "account_sid": "ACa3d5c6a580aea4fa5b8c0717f1076067",
    "url": "https://conversations.twilio.com/v1/Services/IS5083811b3ac44e5e9b52c2b010f8ea3a/Conversations/CH5e1f6d3ef2b446a6b2d285315f8805e0",
    "state": "active",
    "date_created": "2021-12-07T16:28:34Z",
    "messaging_service_sid": "MGd1f04aaf5b520358de5367defc56b317",
    "sid": "CH5e1f6d3ef2b446a6b2d285315f8805e0",
    "attributes": "{\"id\":3953}",
    "bindings": null,
    "chat_service_sid": "IS5083811b3ac44e5e9b52c2b010f8ea3a",
    "links": {
        "participants": "https://conversations.twilio.com/v1/Services/IS5083811b3ac44e5e9b52c2b010f8ea3a/Conversations/CH5e1f6d3ef2b446a6b2d285315f8805e0/Participants",
        "messages": "https://conversations.twilio.com/v1/Services/IS5083811b3ac44e5e9b52c2b010f8ea3a/Conversations/CH5e1f6d3ef2b446a6b2d285315f8805e0/Messages",
        "webhooks": "https://conversations.twilio.com/v1/Services/IS5083811b3ac44e5e9b52c2b010f8ea3a/Conversations/CH5e1f6d3ef2b446a6b2d285315f8805e0/Webhooks"
    }
}

Technical details:

childish-sambino commented 2 years ago

In order to properly debug this issue, please file a support ticket.