PHP: create a list

Hi everyone,

I'm working with the campaign monitor api, the third version (V3).
When i try to create a list, i got this weird message:

array(2) { ["Code"]=> int(101) ["Message"]=> string(14) "Invalid ListID" }

In the documentation, in the post body, it is not written that a ListID have to provided.

I don't use any grabber. I do code it from scratch in php with curl.

Configuration of the tools from the server:

PHP 5.5
Curl 7.19.7

roshodgekiss roshodgekiss, 3 years ago

Hi there, jazzman - mind us asking, are you using the PHP wrapper for our API? You may want to take a look at our create.php sample on GitHub.

A list ID isn't required to create lists, but a client ID is. To get client names & IDs, you can use our get_clients.php sample.

Thanks, jazzman - if you have any questions about this, please don't hesitate to ask.


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor
jazzman, 3 years ago

this is exactly what the documentation said, in order to create a list, we need a the clientID.
as i said, i don't use the php grabber from github.

my request seems to be correctly formed but i got the pasted above: invalid ListID

that's strange...

Phil Phil, 3 years ago

Hi jazzman,

The routes for creating, reading, updating, and deleting lists are structurally the same. They're all /api/v3/lists/{someID}.{xml|json| except that the first takes a ClientID whereas the rest take a ListID. They also differ by which HTTP verb is used. Create uses POST, read uses GET, update is PUT etc.

If you're getting an invalid listID message it's likely one of two things:
1) You're using the wrong HTTP verb, or
2) After creating the list you're making another call which does take a listID, and that call is incorrectly formed.

However, at this stage i'm just speculating. Can you post a bit of your code, and maybe the full request (headers included) so we can take a look? Anonymize it all first - remove the ApiKey and Authentication header, etc.

It seems you don't wish to use the php wrapper, which is fine if that's what you want. But it's written so that details like the exact route and HTTP verb etc can be abstracted away. From a consumer standpoint you're just calling a method. We write the wrappers in order to minimise errors like what you're seeing, so it's definitely worth giving it a shot.

jazzman, 3 years ago
Phil :

Hi jazzman,

The routes for creating, reading, updating, and deleting lists are structurally the same. They're all /api/v3/lists/{someID}.{xml|json| except that the first takes a ClientID whereas the rest take a ListID. They also differ by which HTTP verb is used. Create uses POST, read uses GET, update is PUT etc.

If you're getting an invalid listID message it's likely one of two things:
1) You're using the wrong HTTP verb, or
2) After creating the list you're making another call which does take a listID, and that call is incorrectly formed.

However, at this stage i'm just speculating. Can you post a bit of your code, and maybe the full request (headers included) so we can take a look? Anonymize it all first - remove the ApiKey and Authentication header, etc.

It seems you don't wish to use the php wrapper, which is fine if that's what you want. But it's written so that details like the exact route and HTTP verb etc can be abstracted away. From a consumer standpoint you're just calling a method. We write the wrappers in order to minimise errors like what you're seeing, so it's definitely worth giving it a shot.


Hi Phil,

Thank you for your reply !
Your explication made extremely sense to me.
Before coding, i did read carefully the documentation and that's what i did understand about  ID's and the Verb. It was quite easy to write my wrapper.

I can retrieve without any problem my clientID cause it's a "GET" method

About the possible problem, i did verify and:

- the verb seems correctly defined ==> THAT'S WHAT I THOUGHT
- Even, with curl in console, i do one request, i get this error. I does mean that the problem doesn't come from a possible next call incorrectly formed.

As i'm using the console mode, i will paste my curl call (verbose version):

[root@localhost ~]# curl -v -u "APIKEY:x" https://api.createsend.com/api/v3/lists/CLIENTID.json
* About to connect() to api.createsend.com port 443 (#0)
*   Trying 103.28.41.22... connected
* Connected to api.createsend.com (103.28.41.22) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using SSL_RSA_WITH_RC4_128_SHA
* Server certificate:
*       subject: CN=*.createsend.com,OU=Domain Control Validated,O=*.createsend.com
*       start date: feb 15 22:33:44 2011 GMT
*       expire date: feb 15 22:33:44 2016 GMT
*       common name: *.createsend.com
*       issuer: serialNumber=07969287,CN=Go Daddy Secure Certification Authority,OU=http://certificates.godaddy.com/repository,O="GoDaddy.com, Inc.",L=Scottsdale,ST=Arizona,C=US
* Server auth using Basic with user 'APIKEY'
> GET /api/v3/lists/CLIENTID.json HTTP/1.1
> Authorization: Basic CLEANED
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: api.createsend.com
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Server: csw
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="https://api.createsend.com/api/v3/lists/CLIENTID.json"
< Cache-Control: private
< Content-Type: application/json; charset=utf-8
< P3P: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE"
< Date: Wed, 14 Aug 2013 08:41:19 GMT
< Content-Length: 39
<
* Connection #0 to host api.createsend.com left intact
* Closing connection #0

The problem was all about the request. In my code, i was using CURLOPT_CUSTOMREQUEST to set the type of request. Unfortunately, it was not the right option for a "POST request".
For this, you have use:

curl_setopt($this->curl_channel, CURLOPT_POST, 1);

After cleaning some other things (inner to my code), everything works well !

roshodgekiss roshodgekiss, 3 years ago

Great to hear, jazzman - glad we could help here :D


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor

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