From dc3830ed75fc99a60fbdf507d74753b8a7d39081 Mon Sep 17 00:00:00 2001 From: Gassan Idriss Date: Tue, 9 Jun 2020 13:37:19 -0700 Subject: [PATCH 1/6] Fix for Survey Monkey moving to Cloud Front. Requests with no body content should be null --- src/Client.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index c47b958..c2696a0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -152,9 +152,10 @@ public function sendRequest(RequestInterface $request) private function createRequest($method, $uri, array $options = [], $body = null) { if (empty($body)) { - // Empty arrays and NULL data inputs both need casting to an empty JSON object. - // See https://stackoverflow.com/a/41150809/2803757 - $bodyString = '{}'; + // Survey Monkey moved to CloudFront on 2020-05-23 + // CloudFront issues 403 Forbidden with empty json body + // Previously this was set to an empty json object string. See https://stackoverflow.com/a/41150809/2803757 + $bodyString = null; } elseif (is_array($body)) { $bodyString = json_encode($body); } From f00e3337940b227d88fe308272173c5daf9090e3 Mon Sep 17 00:00:00 2001 From: Gassan Idriss Date: Tue, 9 Jun 2020 13:43:46 -0700 Subject: [PATCH 2/6] Bump version patch --- CHANGELOG | 2 ++ README.md | 2 +- composer.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 04a6bec..3938970 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +v1.1.1: + - Issue 28 - Fix for Cloud Front returning 403 with an empty json object for the request content v1.1.0: - Added support for the following API endpoints: /survey_languages diff --git a/README.md b/README.md index e870206..996a5f9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A simple SurveyMonkey API wrapper for version 3 of their API. Add the following to your composer.json under require: "require": { - "ghassani/surveymonkey-v3-api-php": "1.1.0" + "ghassani/surveymonkey-v3-api-php": "1.1.1" }, # Usage diff --git a/composer.json b/composer.json index 729e777..2756e4c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ghassani/surveymonkey-v3-api-php", - "version" : "1.1.0", + "version" : "1.1.1", "authors": [ { "name": "Gassan Idriss", From afd1997e70eea3f1c2f33b322d349582785f700a Mon Sep 17 00:00:00 2001 From: Timothy Date: Thu, 16 Jul 2020 11:23:58 +0100 Subject: [PATCH 3/6] Fix for copyCollectorMessage returning 1001 error * Data now set * Data forces to string, if ID is set as INT 1002 error returned --- src/Api/CollectorsTrait.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Api/CollectorsTrait.php b/src/Api/CollectorsTrait.php index e5f7db8..769d920 100644 --- a/src/Api/CollectorsTrait.php +++ b/src/Api/CollectorsTrait.php @@ -172,12 +172,10 @@ public function createCollectorMessage($collectorId, array $data = []) public function copyCollectorMessage($collectorId, $fromCollectorId, $fromMessageId, $includeRecipients = false) { return $this->sendRequest( - $this->createRequest('POST', sprintf('collectors/%s/messages', $collectorId), [ - 'query' => [ - 'from_collector_id' => $fromCollectorId, - 'from_message_id' => $fromMessageId, - 'include_recipients' => (bool)$includeRecipients, - ] + $this->createRequest('POST', sprintf('collectors/%s/messages', $collectorId), [], [ + 'from_collector_id' => (string)$fromCollectorId, + 'from_message_id' => (string)$fromMessageId, + 'include_recipients' => (bool)$includeRecipients, ]) ); } From 1306c9db34b504cd97f373719bd08c99d43ded31 Mon Sep 17 00:00:00 2001 From: Gassan Idriss Date: Thu, 16 Jul 2020 11:29:30 -0700 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 996a5f9..b9a4fb2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A simple SurveyMonkey API wrapper for version 3 of their API. Add the following to your composer.json under require: "require": { - "ghassani/surveymonkey-v3-api-php": "1.1.1" + "ghassani/surveymonkey-v3-api-php": "1.*" }, # Usage From 324ee7b6ab8fb6e44492e72e02ee15595fd35e24 Mon Sep 17 00:00:00 2001 From: Gassan Idriss Date: Thu, 16 Jul 2020 11:29:45 -0700 Subject: [PATCH 5/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2756e4c..a55b03a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ghassani/surveymonkey-v3-api-php", - "version" : "1.1.1", + "version" : "1.1.2", "authors": [ { "name": "Gassan Idriss", From f658628e5eeb3569f0497d18ad708fb0b56a140c Mon Sep 17 00:00:00 2001 From: Altrozero Date: Fri, 17 Jul 2020 14:36:32 +0100 Subject: [PATCH 6/6] Fix to sendCollectorMessage returning 1002 when no data --- src/Api/CollectorsTrait.php | 2 +- src/Client.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/CollectorsTrait.php b/src/Api/CollectorsTrait.php index e5f7db8..f4d7347 100644 --- a/src/Api/CollectorsTrait.php +++ b/src/Api/CollectorsTrait.php @@ -265,7 +265,7 @@ public function deleteCollectorMessage($collectorId, $messageId) */ public function sendCollectorMessage($collectorId, $messageId, \DateTime $scheduledDate = null) { - $data = $scheduledDate ? [ 'scheduled_date' => $scheduledDate->format(DATE_ATOM) ] : []; + $data = $scheduledDate ? [ 'scheduled_date' => $scheduledDate->format(DATE_ATOM) ] : new \stdClass(); return $this->sendRequest( $this->createRequest('POST', sprintf('collectors/%s/messages/%s/send', $collectorId, $messageId), [], $data) diff --git a/src/Client.php b/src/Client.php index c2696a0..300f78e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -156,7 +156,7 @@ private function createRequest($method, $uri, array $options = [], $body = null) // CloudFront issues 403 Forbidden with empty json body // Previously this was set to an empty json object string. See https://stackoverflow.com/a/41150809/2803757 $bodyString = null; - } elseif (is_array($body)) { + } elseif (is_array($body) || $body instanceof \stdClass) { $bodyString = json_encode($body); }