Creating Campaigns on API v3


I've been really struggling to use the API to create a draft campaign. I'm consistently receiving either error 400 or 500 and I don't have a clue what is wrong.

This is the request:

$result = $wrap->create($client, array(
    'Subject' => $subject,
        'Name' => $campaignName,
    'FromName' => $fromName,
    'FromEmail' => $fromEmail,
    'ReplyTo' => $replyto,
    'HtmlUrl' => '',
    'TextUrl' => '',
    'ListIDs' => array('AA77CB8D21058B56', '9A684341AFD2414D'),
    'SegmentIDs' => array('2CEC985E9676DFE7', '680BD799ED61B678')

The above gives me this response:

object(stdClass)#22 (2) {
  string(68) "Sorry, we've run into a problem. Please try again or contact support"

If I try just giving one list id and one segment id or even just one list id like so:

$result = $wrap->create($client, array(
                    'Subject' => 'test subject',
                    'Name' => 'test campaign name',
                    'FromName' => 'test from name',
                    'FromEmail' => '',
                    'ReplyTo' => '',
                    'HtmlUrl' => '',
                    'TextUrl' => '',
                    'ListIDs' => 'AA77CB8D21058B56',
                    'SegmentIDs' => '2CEC985E9676DFE7'

I receive a 400 error:

object(stdClass)#22 (2) {
  string(110) "Failed to deserialize your request. 
Please check the documentation and try again.
Fields in error: campaign"

I'd really appreciate it if anyone could give me a hint as to what I am doing wrong here.

Thanks in advance!

jamesd jamesd, 6 years ago

Hey there,

At a quick glance, it would appear that you're not using the correct ID values for your lists and segments. You appear to be using the values found in the URL for a list or segment in the app rather than using the API to retrieve the IDs of the relevant lists/segments.

You should not use ID values from the query string in the app. You should use the ID corresponding to the list/segment after retrieving the details of the list/segment using the API:

See Getting a client's subscriber lists and Getting a list's segments in the API docs.

jspurling, 6 years ago

ok I should have realised that - I just assumed they would be the same. I'll give that a go and confirm here if that fixes the problem.

and thank you very much!

jspurling, 6 years ago

Just to confirm that did the trick.

One thing worth noting is that in the php wrapper comments in csrest_campaigns.php it says that the text url is optional, which it is not.

tobyb tobyb, 6 years ago

Thanks for the heads up, the comments will be fixed in future versions.

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free