spatie / laravel-mailcoach-sdk

An SDK to easily work with the Mailcoach API in Laravel apps
https://mailcoach.app
MIT License
26 stars 7 forks source link

Amazing, but -> The GET method is not supported for route api/subscribers/XXXX/tags. Supported methods: POST, DELETE. #29

Open elfeffe opened 2 hours ago

elfeffe commented 2 hours ago

I'm using Laravel 10, and latest mailcoach sdk (with a self hosted mailcoach, latest version). And guzzlehttp/guzzle 7.9.2

I try to do $mailcoachSubscriber->addTags(['test']); I have this code (MakesHttpRequests) to try to debug:

if (! $this->isSuccessful($response)) {
            dump($verb);
            dump($uri);
            dump($payload);
            dd($response->getBody()->getContents());
            $this->handleRequestError($response);

            return null;
        }

I get :

"POST" // vendor/spatie/mailcoach-sdk-php/src/MakesHttpRequests.php:48
"subscribers/XXXX/tags" // vendor/spatie/mailcoach-sdk-php/src/MakesHttpRequests.php:49
array:1 [
  "tags" => array:1 [
    0 => "test"
  ]
] // vendor/spatie/mailcoach-sdk-php/src/MakesHttpRequests.php:50
"""
{\n
    "message": "The GET method is not supported for route api/subscribers/XXXX/tags. Supported methods: POST, DELETE."\n
}
""" // vendor/spatie/mailcoach-sdk-php/src/MakesHttpRequests.php:51

Using curl in command line: curl -X POST "https://xxx/api/subscribers/XXXX/tags" -H "Authorization: Bearer XXXX" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"tags":["test"]}'

It works, so it is not mailcoach.

This is the guzzle call

GuzzleHttp\Psr7\Request^ {#4880
  -method: "POST"
  -requestTarget: null
  -uri: GuzzleHttp\Psr7\Uri^ {#4881
    -scheme: "https"
    -userInfo: ""
    -host: "XXXX"
    -port: null
    -path: "/api//subscribers/XXXX/tags"
    -query: ""
    -fragment: ""
    -composedComponents: null
  }
  -headers: array:5 [
    "Authorization" => array:1 [
      0 => "Bearer XXXX"
    ]
    "Accept" => array:1 [
      0 => "application/json"
    ]
    "User-Agent" => array:1 [
      0 => "GuzzleHttp/7"
    ]
    "Content-Type" => array:1 [
      0 => "application/x-www-form-urlencoded"
    ]
    "Host" => array:1 [
      0 => "XXXX"
    ]
  ]
  -headerNames: array:5 [
    "authorization" => "Authorization"
    "accept" => "Accept"
    "user-agent" => "User-Agent"
    "content-type" => "Content-Type"
    "host" => "Host"
  ]
  -protocol: "1.1"
  -stream: GuzzleHttp\Psr7\Stream^ {#4891
    -stream: stream resource {@3313
      wrapper_type: "PHP"
      stream_type: "TEMP"
      mode: "w+b"
      unread_bytes: 0
      seekable: true
      uri: "php://temp"
      options: []
    }
    -size: null
    -seekable: true
    -readable: true
    -writable: true
    -uri: "php://temp"
    -customMetadata: []
  }
}

This is a POST call.

elfeffe commented 2 hours ago
 $response = Http::withHeaders([
                'Authorization' => 'Bearer XXXX',
                'Accept' => 'application/json',
                'Content-Type' => 'application/json',
            ])->post('https://XXX/api/subscribers/XXXX/tags', [
                'tags' => ['test'],
            ]);

Also works :)