phpfui / ConstantContact

MIT License
16 stars 7 forks source link

List of Campaigns #9

Closed degive closed 2 years ago

degive commented 2 years ago

With the ConstantContact API you can get a list of Campaigns by calling the V3\Emails but when I look at your docs, I only see V3\Email\Activities, so how do I get a list of Campaigns with yours?

phpfui commented 2 years ago

Maybe http://phpfui.com/?n=PHPFUI%5CConstantContact%5CV3&c=Emails ?

Also just Email as well, but probably not what you're looking for.

On Mon, Aug 1, 2022, 11:12 AM Michel @.***> wrote:

With the ConstantContact API you can get a list of Campaigns by calling the V3\Emails but when I look at your docs, I only see V3\Email\Activities, so how do I get a list of Campaigns with yours?

— Reply to this email directly, view it on GitHub https://github.com/phpfui/ConstantContact/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYW6SYGSR3YGM5XJAJRPN3VXAHQVANCNFSM55INSTXA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

phpfui commented 2 years ago

If this answered your question, please close this issue. If not, let me know what still does not work for you. Thanks!

degive commented 2 years ago

No, it does not work.

/V3/Emails/{campaign_id} would return info about one campaign. But V3/Emails should return a list of campaigns and it does not look like you implemented this. here is what it returns:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function PHPFUI\ConstantContact\V3\Emails::__construct(), 0 passed

Here is the ConstantContact Docs on that: https://developer.constantcontact.com/api_reference/index.html#!/Email_Campaigns/retrieveEmailCampaignsUsingGET GET a Collection of Email Campaigns Get /emails

Use this method to list and get details about your email campaigns. By default, this method returns all email campaigns for the user account including deleted email campaigns. To get email campaigns within a date-range, use the after_date and before_date query parameters.
phpfui commented 2 years ago

Since you want a list of campaigns, you should use the plural form of the API. Constant Contact did not design the API correctly, so they use end points that just return a single item with a plural name, which is incorrect. A plural end point should return a list of items, never only a single item. I have corrected this problem in the naming conventions for this library.

Also, due to limitations in PHP, it was easier to separate out the plural end points from the singular endpoints.

I think you want this call: http://phpfui.com/?n=PHPFUI%5CConstantContact%5CV3&c=Emails Look at the get method. Should do what you want. The Email endpoint (http://phpfui.com/?n=PHPFUI%5CConstantContact%5CV3&c=Email) will do things like get, update or delete one Email Campaign. It should probably do add (post) as well, not sure why post is on the plural endpoint, but this library was created be a generic program that parses the YAML file, so it could make sense for some things and not others.

Hope this helps.

degive commented 2 years ago

Bruce, I am calling the Plural version: $camp = new PHPFUI\ConstantContact\V3\Emails();

And it returns an error: Fatal error: Uncaught ArgumentCountError: Too few arguments to function PHPFUI\ConstantContact\V3\Emails::__construct(), 0 passed

phpfui commented 2 years ago

Ah, you are constructing the object. It needs the client to communicate with the server. Sorry I did not see this before.

You need to do:

$campEndPoint = new PHPFUI\ConstantContact\V3\Emails($client);  // see docs on how to make a client

$campaigns = $campEndPoint->get();
do {
  print_r($campaigns);
  campaigns = $campEndPoint->next();
} while (campaigns);
degive commented 2 years ago

I feel totally stupid. How could I have missed that?

So sorry to waste your time!

phpfui commented 2 years ago

Not a problem. Welcome to programming! Glad you found the library and are using it.