Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Survey Monkey Api Php Client Laravel Package

davidwnek/survey_monkey_api_php_client

PHP client library for the SurveyMonkey API. Install via Composer, regenerate autoload as needed, then use the client in your project to call SurveyMonkey endpoints and work with surveys, collectors, and responses.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Package

    composer require davidwnek/survey_monkey_api_php_client
    

    Note: As this is a legacy package, ensure your PHP version (7.4+) and dependencies are compatible.

  2. Configure the Client Create a config file (e.g., config/survey_monkey.php) with your API credentials:

    return [
        'access_token' => env('SURVEYMONKEY_ACCESS_TOKEN'),
        'base_uri'     => 'https://api.surveymonkey.com/v3',
        'default_page_size' => env('SURVEYMONKEY_PAGE_SIZE', 25), // New: Configurable default page size
    ];
    
  3. First Use Case: Fetch Surveys with Pagination

    use Davidwnek\SurveyMonkeyApi\Client;
    
    $client = new Client(config('survey_monkey.access_token'));
    $surveys = $client->get('/surveys', [
        'page_size' => config('survey_monkey.default_page_size') // Leverage new pagination support
    ]);
    

Where to Look First

  • API Docs: SurveyMonkey API v3 (official reference).
  • Package Source: GitHub for pagination-related changes.
  • Laravel Service Provider: Register the client in config/app.php for dependency injection.

Implementation Patterns

Workflows

  1. Survey Management

    • Create a Survey (unchanged):
      $surveyData = ['title' => 'Customer Feedback', 'description' => 'Collect feedback'];
      $client->post('/surveys', $surveyData);
      
  2. Enhanced Response Handling with Pagination

    • Fetch Responses with Custom Page Size:
      $responses = $client->getResponses('/surveys/123/responses', [
          'page_size' => 100, // New: Explicit page size override
          'page' => 1
      ]);
      
    • Iterate Through All Responses:
      $page = 1;
      $maxPageSize = config('survey_monkey.default_page_size');
      do {
          $responses = $client->getResponses("/surveys/{survey_id}/responses", [
              'page' => $page,
              'page_size' => $maxPageSize
          ]);
          // Process responses...
          $page++;
      } while (!empty($responses['next_page']));
      
  3. Webhooks Integration (unchanged): Use Laravel’s queue:work to process SurveyMonkey webhook payloads.

Integration Tips

  • Laravel Facade (unchanged): Create a facade for cleaner syntax with pagination support:

    SurveyMonkey::getResponses('/surveys/123/responses', ['page_size' => 50]);
    
  • API Rate Limiting with Pagination: Cache paginated responses efficiently:

    $responses = Cache::remember(
        "survey_{$surveyId}_responses_page_{$page}",
        now()->addMinutes(5),
        function () use ($client, $surveyId, $page) {
            return $client->getResponses("/surveys/{$surveyId}/responses", [
                'page' => $page,
                'page_size' => config('survey_monkey.default_page_size')
            ]);
        }
    );
    
  • Error Handling (unchanged): Wrap API calls in a try-catch for robust pagination handling:

    try {
        $responses = SurveyMonkey::getResponses('/surveys/123/responses', [
            'page_size' => 1000 // Max allowed by SurveyMonkey
        ]);
    } catch (\Davidwnek\SurveyMonkeyApi\Exception\ApiException $e) {
        Log::error("Pagination error: " . $e->getMessage());
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package (unchanged):

    • Last release is from 2018. Test thoroughly or consider forking.
  2. Pagination Quirks:

    • Page Size Limits: SurveyMonkey enforces a max page size of 1000. Attempting larger values will fail.
      // Will throw an error
      $client->getResponses('/surveys/123/responses', ['page_size' => 2000]);
      
    • Default Behavior: If page_size isn’t specified, the package may default to 25 (check SurveyMonkey’s API docs for actual default).
  3. Authentication Issues (unchanged):

    • Ensure access_token has responses:read permissions for paginated response fetching.
  4. Data Serialization (unchanged):

    • Complex nested data may still require manual flattening.

Debugging

  • Enable Guzzle Debugging (unchanged): Log requests to inspect pagination parameters:

    $client = new Client($token, ['debug' => true]);
    
  • Validate Paginated Responses:

    $validator = Validator::make($responses, [
        'data' => 'array',
        'data.*' => 'array',
        'data.*.id' => 'required|string',
        'page_size' => 'integer|max:1000', // Validate against SurveyMonkey limits
    ]);
    

Extension Points

  1. Custom Pagination Middleware: Add middleware to enforce page size limits:

    $client->getMiddleware()->push(
        new class {
            public function __invoke($request, $options) {
                $pageSize = $request->getQuery('page_size');
                if ($pageSize && $pageSize > 1000) {
                    $request->setQuery('page_size', 1000);
                }
                return $request;
            }
        }
    );
    
  2. Decorate for Bulk Operations: Extend the client to handle bulk response fetching:

    class BulkSurveyMonkey {
        public function getAllResponses($surveyId) {
            $allResponses = [];
            $page = 1;
            $pageSize = config('survey_monkey.default_page_size');
            while (true) {
                $responses = $client->getResponses("/surveys/{$surveyId}/responses", [
                    'page' => $page,
                    'page_size' => $pageSize
                ]);
                $allResponses = array_merge($allResponses, $responses['data']);
                if (empty($responses['next_page'])) break;
                $page++;
            }
            return $allResponses;
        }
    }
    
  3. Webhook Verification (unchanged): Verify signatures for webhook payloads containing paginated data.

  4. Configurable Defaults: Override default page size per environment:

    // config/survey_monkey.php
    'default_page_size' => env('SURVEYMONKEY_PAGE_SIZE', function() {
        return app()->environment('production') ? 100 : 25;
    }),
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels