Adding a New Option to a Category Field
Hello, I'm attempting to write code to add a new option to a Category field within an app.e.g: A field has options 1, 2, 3, 4, I'd like to add a new option "5".Below is my code (PHP) thus far, but it only succeeds in removing ALL the options for the category field!Could someone point out what I'm doing wrong here?------$fieldAttributes = array ( 'label' => 'Status', 'type' => 'Category', 'config' => [ 'description' => 'Hi', 'label' => 'Category', 'required' => false, 'settings' => [ 'multiple' => false, 'options' => [ [ 'status' => 'active', 'text' => 'WHY', 'color' => 'D1F3EC', ], ] ] ]);PodioAppField::update($appID, $fieldID, $fieldAttributes);

  • Hi Ashwin, The 'update' method updates the 'config' of a field. So your request should look something like this: $fieldAttributes = array ( 'label' => 'Status', 'required' => false, 'settings' => [ 'multiple' => false, 'options' => [ [ 'status' => 'active', 'text' => 'WHY', 'color' => 'D1F3EC', ], ] ]);PodioAppField::update($appID, $fieldID, $fieldAttributes); Note that this will overwrite the current config - so existing options will be deleted.If you want to add a new option you will have to put all existing options with their IDs into the request - eg.: $fieldAttributes = array ( 'label' => 'Status', 'required' => false, 'settings' => [ 'multiple' => false, 'options' => [ [ id => 1, 'text' => 'Existing option with id=1', ], [ id => 2, 'text' => 'New option with id=2', ] [ 'text' => 'New option - with auto-generated id', ] ] ]);PodioAppField::update($appID, $fieldID, $fieldAttributes); brMarek
This question is closed.