Skip to content

Don't include unused parameters in Trello API requests #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/Trello/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ abstract class AbstractApi implements ApiInterface
*/
public static $fields;

/**
* These are values that are being passed to Trello in our requests, that are not needed,
* and are causing Trello to give a "Error parsing body: too many parameters" error.
*
* @var array
*/
protected $ignore_on_update_fields = [
'actions',
'board',
'list',
'attachments',
'idLabels',
'badges',
'checklists',
'stickers',
'labels',
'idChecklists',
'members',
'membersVoted',
'descData',
];

/**
* @param Client $client
*/
Expand Down Expand Up @@ -186,6 +208,8 @@ protected function postRaw($path, $body, $requestHeaders = array())
*/
protected function patch($path, array $parameters = array(), $requestHeaders = array())
{
$parameters = $this->removeExcessParameters($parameters);

$response = $this->client->getHttpClient()->patch(
$path,
$this->createParametersBody($parameters),
Expand All @@ -212,6 +236,8 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr
}
}

$parameters = $this->removeExcessParameters($parameters);

$response = $this->client->getHttpClient()->put(
$path,
$this->createParametersBody($parameters),
Expand Down Expand Up @@ -351,4 +377,23 @@ protected function validateAtLeastOneOf(array $atLeastOneOf, array $params)
implode('", "', $atLeastOneOf)
));
}

/**
* Remove our fields that don't need to be passed to Trello.
* This prevents trello from throwing a "Error parsing body: too many parameters" error
* on requests with a card that has a lot of content.
*
* @param array $parameters
*
* @return array
*/
protected function removeExcessParameters($parameters)
{
// Remove our fields that don't need to be passed to Trello.
foreach($this->ignore_on_update_fields as $ignored_field) {
unset($parameters[$ignored_field]);
}

return $parameters;
}
}