Creating Campaigns on API v3

Hi,

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' => 'http://www.jolora.co.uk/html/left_sidebar.html',
    'TextUrl' => 'http://www.jolora.co.uk/html/test.txt',
    'ListIDs' => array('AA77CB8D21058B56', '9A684341AFD2414D'),
    'SegmentIDs' => array('2CEC985E9676DFE7', '680BD799ED61B678')
));

The above gives me this response:

object(stdClass)#22 (2) {
  ["Code"]=>
  int(500)
  ["Message"]=>
  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' => 'me@example.com',
                    'ReplyTo' => 'me@example.com',
                    'HtmlUrl' => 'http://www.jolora.co.uk/html/left_sidebar.html',
                    'TextUrl' => 'http://www.jolora.co.uk/html/test.txt',
                    'ListIDs' => 'AA77CB8D21058B56',
                    'SegmentIDs' => '2CEC985E9676DFE7'
                ));

I receive a 400 error:

object(stdClass)#22 (2) {
  ["Code"]=>
  int(400)
  ["Message"]=>
  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, 5 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, 5 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, 5 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, 5 years ago

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

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098