Using ConvioApi.js to update constituent records

Options

Been hacking at this for some time now, and for the life of me I cannot seem to get the "update" method to work. It always returns error code 5, an apparent lack of an auth token even though I'm passing one...

I've created a fairly simple survey form that attempts to update a constituent's primary_email if it is blank before submitting the form.

First, if the user is not logged in, they enter their member id and last name, and the form posts to CRConsAPI with method=authenticateUser.

The success_redirect points back to this survey page (actually a page builder page with a survey form in it).

Now that the user is authenticated, it displays the survey form with hidden fields for their cons_id and auth token (]).

Since some of our constituent records are imported without email addresses, we need to update their record before continuing.

My validation script looks something like this:

var api = new ConvioApiClient("open", "/api/api_client.html", "json");

function validate(form) {


if ( form.updating.value == "true" ) {

function updateComplete(data, status) {

if ( status == 200 ) {

form.updating.value = "false";

form.submit();

}

else {

alert(data.errorResponse.message + "(" + data.errorResponse.code + ")");

}

}

var params = "cons_id=" + form.cons_id.value + "&primary_email=" + form.cons_email.value.replace("@,%40") + "&sso_auth_token=" + form.auth.value;

api.callConsAPI("update", updateComplete, params );

return false;

}

else {

return true;

}

}

The params string looks correct, the auth token is there, but it always says "the requested method is not allowed."

Any ideas of what I'm doing wrong?

Tagged:

Comments

  • To bump this and add something relevant, I'm not sure if this has been addressed, but part of the reason we have to update blank email fields has to do with CMS pages being inaccessable to users who are logged in but lack a primary_email. This only happens when importing constituents from our DB, since there's no other way to create a constituent record without an email online. PageBuilder, Surveys, Donation forms, etc are just fine, but anything served up by CMS breaks with the following error:

    500 Servlet Exception



    java.lang.IllegalArgumentException: Email address cannot be null or empty

    I know other users have seen simiarl servlet errors for similar reasons, but I haven't seen this particular one in the forums.

    Any suggestions for overcoming this? For now we're trying to simply embed a lot of conditional tests for blank emails, then presenting an update form that posts to CRConsAPI. Of course, this doesn't work on CMS pages, since the error kills it before the conditional can even run.

    We've also built a query to find consituents with blank email, dowload a mail-merge with contact_ids, insert a primary_email column with each value as "empty," then import and update each constituent. At least this way the field isn't blank, and I can test for primary_email="empty" on any page, but it's definitely not optimal to have to do this every week.

    Thoughts?

Categories