ActiveCampaign / activecampaign-api-php

MIT License
115 stars 76 forks source link

Campaign list filter with all Ids #82

Closed mattpramschufer closed 6 years ago

mattpramschufer commented 7 years ago

I am able to get the sample code to work from https://www.activecampaign.com/api/example.php?call=campaign_list to return all campaigns with a filter applied for sending date. However I can not get it to work with this library package.

I have the following

    $params = [
        'filters[sdate_since_datetime]' => '2017-10-30 05:00:00'
    ];

    $campaigns = $ac->api( "campaign/list?ids=all", $params);

    $results = [];

    foreach($campaigns as $campaign){
        $results[] = [
            'id' => $campaign->id,
            'sdate' => $campaign->sdate,
            'name' => $campaign->name
        ];
    }
    echo "<pre>";
    print_r( $results );
    echo "</pre>";

The first issue is that you can't have 'ids' => 'all in the $params array. If you do that it will return no results. The second issue is that it doesn't matter what I pass in the $params array, it never actually gets passed.

What am I doing wrong here?

cristiangrama commented 6 years ago

campaign/list does not take post data so you'll have to add all the query params like this

$params = [
    'ids' => 'all',
    'filters[sdate_since_datetime]' => '2017-10-30 05:00:00'
];

$params = http_build_query($params);

$campaigns = $ac->api( "campaign/list?{$params}");