mailchimp-api icon indicating copy to clipboard operation
mailchimp-api copied to clipboard

Getting PUT, PATCH etc to work

Open ghost opened this issue 6 years ago • 2 comments

Firstly, thanks heaps for making this available. So much simpler than other offerings In our implementation we noticed that when we are doing a simple subsrcribe that if the subscriber is already noticed the request gets bounced.

We tried changing the request to PUT instead of POST - MC docs seem to suggest that PUT will update or add as appropriate.

The API then returned an error - PUT not allowed Did two things

  • In the request added an email address md5 hash
  • In the CURL request inside the MC class added
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/vnd.api+json',
            'Content-Type: application/vnd.api+json',
            'Authorization: apikey ' . $this->api_key,
            **'Allow: PUT, PATCH, GET, POST'**
        ));

It's all good now. Thanks again

ghost avatar Dec 16 '17 10:12 ghost

Yes, sounds good. Please send a PR.

drewm avatar Feb 23 '18 09:02 drewm

I've seen MC respond with a "use PUT" error on a PUT request on occasion as well. This snippet from https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

  The Allow header field MAY be provided with a PUT request to
  recommend the methods to be supported by the new or modified
  resource. The server is not required to support these methods and
  SHOULD include an Allow header in the response giving the actual
  supported methods.

suggests the Allow header should only be added to the client request if its a PUT and seems to suggest only valid/desired methods should be listed.

If/when I see this error go by again, I'll see if I can get a repeatable test case. If I can, I'll create a PR if this is still outstanding.

pdbreen avatar Feb 23 '18 11:02 pdbreen