How do I test against a custom field value?

What I'm trying to do here is to create a 'simple' script that will check a random number against what is in the CM db. The way it works is I'm using a hidden field to insert a random 8 digit number into a custom field (what/why you ask? my boss wants to send a "registration code" in the confirmation email, and then when the customer uses said code to make their purchase, I want to check that it's a valid number), which is then sent to the user in the confirmation email. I've got everything working as far as creating and inserting the number (using a few simple lines of PHP, nothing API related), and I can see that the number is making it into the custom field, as it's getting passed back to me in the confirmation email, and I can see it in the subscriber details page.

Now I just need to figure out how to use the API to check that the number is actually in the CM db, and I also need to test that it's creation timestamp is less than 24 hours old. Yes I know those are two separate things, but I just wanted to give you all the full picture.

I know that they will belong to a specific segment, so I'm thinking that I need to do something like segment_name->custome_field_name->value but maybe I'm barking up the wrong tree ...

Any suggestions or pointers in the general direction I should be going?

Jonny, 6 years ago

Ok, I've figured out how to return one subscriber, based on their email address, ie{list ID}.json? but that's not quite what I want :/ I tried swapping out '?email=' with 'customfield=' but that just returns an 'invalid email address' error.

I would really appreciate if a CM employee could tell me if what I'm trying to do is even possible, because if it's not I don't want to keep hitting my head against it.

Thanks in advance!

Jonny, 6 years ago

Hmmm well it seems like I'm pretty much on my own on these boards ;-) Anyway I think what I'm going to do is send a link in the plaintext email that looks like this[email]&licence=[Licence,fallback=]

That way the user doesn't have to enter anything on the purchase page, and we have the email address and can do a lookup with the CM API to confirm authenticity and time-stamp (which I've still yet to figure out but I think it's well within reach).

tobyb tobyb, 6 years ago

That'll definitely work Jonny. As long as you have the email address you can grab all a subscribers custom fields with this method:

Jonny, 6 years ago

@tobyb sorry for the idiotic question, but how do I use $_GET programmatic-ally? Yes if I do what is shown in the link you posted, in a browser address bar, it hits me with the authentication dialog and then gives me the json result, but obviously I need to do it in the code, not manually. I've looked at the sample contained in the php wrapper files, located at /samples/subscriber/get.php, but that is entirely different, and I can see no way to choose json/xml, it simply returns an array (which I'm having zero luck in traversing). Obviously I'm quite green with php :( I'll keep banging my head against it but any pointers in the right direction would be most helpful!

Jonny, 6 years ago

It's all good, I've got my prototype working :)

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