API v2 updateContact problem

MikeF145
Regular Participant

API v2 updateContact problem

Hi there,

I'm working with the new API (v2) and have been able to successfully perform a number of operations but one that I'm having trouble with is updating an existing contact. I'm using the I/O docs to test (https://constantcontact.mashery.com/io-docs) as well as the java wrapper library, both haven't worked for me.

On the I/O docs test page if I perform a GET for a specific contact I recieve back a response body with the JSON for the contact correctly (note that I have an api key and auth token already and have no issues with the OAuth process). If I then select the content (using the handy link on the test page) and paste it into request body for the PUT method for updating, I recieve:

[{
    "error_key": "json.payload.invalid",
    "error_message": "Unable to parse JSON payload."
}]

The java wrapper is failing as well with a slightly different message: CUrlRequestError [errorKey=http.status.conflict, errorMessage=There was a conflict between the supplied data and the existing resource.]]

Any help you can provide is appreciated.

Mike F
19 REPLIES 19
Shannon_W
Employee

Hi Mike,

 

I just tested based on the steps you took, but am not able to reproduce.  What browser are you using (I wonder if the select content feature isn't working properly in it)?  If you have more than one browser, can you reproduce the problem in both?

 

What is the JSON payload for the request (&response) body?

 

Best Regards,

Shannon W.

API Support Specialist

MikeF145
Regular Participant

Hi Shannon,

 

Here's the payload, with personal details removed w/ <omit>

 

{
    "id": "3",
    "status": "UNCONFIRMED",
    "fax": "",
    "addresses": [{
        "id": "2",
        "line1": "<omit>",
        "line2": "",
        "line3": "",
        "city": "<omit>",
        "address_type": "PERSONAL",
        "state_code": "BC",
        "country_code": "ca",
        "postal_code": "<omit>",
        "sub_postal_code": ""
    }, {
        "id": "3",
        "line1": "",
        "line2": "",
        "line3": "",
        "city": "",
        "address_type": "BUSINESS",
        "state_code": "",
        "country_code": "",
        "postal_code": "",
        "sub_postal_code": ""
    }],
    "notes": [],
    "confirmed": false,
    "lists": [{
        "id": "1",
        "status": "ACTIVE"
    }],
    "source": "",
    "email_addresses": [{
        "id": "1",
        "status": "UNCONFIRMED",
        "confirm_status": "UNCONFIRMED",
        "opt_in_source": "ACTION_BY_VISITOR",
        "opt_in_date": "2008-10-03T16:04:22.282Z",
        "email_address": "mike@alluradirect.com"
    }],
    "prefix_name": "",
    "first_name": "",
    "middle_name": "",
    "last_name": "",
    "job_title": "",
    "company_name": "",
    "home_phone": "",
    "work_phone": "",
    "cell_phone": "",
    "custom_fields": [{
        "name": "CustomField2",
        "value": "not yet"
    }],
    "created_date": "2003-09-22T22:01:02.933Z",
    "modified_date": "2009-11-25T23:24:41.352Z",
    "source_details": ""
}

 

With FF 20.0, get response: "error_key": "json.payload.invalid", "error_message": "Unable to parse JSON payload."

 

With Chrome 26.0.1410.43 m I get response "error_key": "json.payload.invalid", "error_message": "Unable to parse JSON payload."

 

With IE 9.0.8112.16421 I get response "error_key": "http.status.conflict",    "error_message": "There was a conflict between the supplied data and the existing resource."

 

I'm starting to suspect that I cannot update status=UNCONFIRMED contacts. If that's the case it's np and I'll use a different contact to test with. But the different error response are a bit confusing if so...interesting that the response in IE corresponds with what I see when using the java wrapper.

 

Anyway thanks for getting back to me, let me know if anything stands out.

 

cheers,

 

Mike F

Hi Mike,

 

We do appear to be having an issue with rejecting valid JSON payloads in some cases.  We are looking into it on our side.  Thanks for reporting this, and we'll keep you posted here.

 

Best Regards,

Shannon W.

API Support Specialist

Hi Mike,

 

We're still working on the I/O Docs returning the invalid JSON error message with good JSON being passed in for both Chrome and Firefox.  The message you received back when using IE may actually be valid (conflict).  In IE, can you do a GET to a contact, and PUT the exact same JSON received successfully?

 

The (quite possibly valid) error about a conflict means that the system wasn't able to resolve the information in the payload with the information on file.  It could happen if a different contact ID was referenced in the payload than the contact ID referenced in the URL, for example.  It could also happen if an email address that was already in the system was referenced by another contact ID (contactID/email address mismatch).

 

Doing a GET/PUT with the same payload and to the same URL will help root that out as a cause for the failure.  Thanks!

 

Best Regards,

Shannon W.

API Support Specialist

MikeF145
Regular Participant

Hi Shannon,

 

Just tried IE again and received the same error msg: 'There was a conflict between the supplied data and the existing resource'

 

Just to be clear on the use case:

 

1) I'm retreiving an individual contact using GET: Retrieve a contact with a specified Contact ID

2) Select content in response body, copy.

3) Paste JSON into PUT: Modify a contact with specified contactID. Enter the exact same contact ID as entered during the GET. Content-Type defaults to application/json. action_by defaults to ACTION_BY_OWNER

4) Click Try it!

 

hth

Mike F

Hi Mike,

 

I've tried to replicate what you're seeing several times, but can't seem to.  The requests go through for me.  I've tried confirmed and unconfirmed contacts to see if there was some issue surrounding that, but can GET and PUT the resultant payloads just fine.  I've used IE8 and IE9 in my testing, as well as chrome and firefox.

 

Can you do a successful GET and PUT for any contact in your account?

Are you making ANY changes to the payload before doing the PUT?

 

Here is a screencast of me doing what I think you're trying to do.

 

Best Regards,

Shannon W.

API Support Specialist

MikeF145
Regular Participant

Hi Shannon,

 

Still having same issues. I watched your screencast, but it does not display the response body after the PUT, just the request body which I assume is simply what was posted. Can you show what the expected response body should be? I've tested this with a few other contacts with the same result.The response body I receive contains the errors.

 

Mike

Mike F

Sorry Mike, I hadn't noticed that I was getting the error as well!  I suppose I expected it to be in large red print.  This is a defect on our side that we need to look into.  Thanks for your patience.

 

Best Regards,

Shannon W.

API Support Specialist

MikeF145
Regular Participant

Just bumping this thread to see if there has been any activity on a solution.

Mike F

Hi Mike,

 

This is something that we had to file a bug with Mashery to get resolved, and they are reporting that a fix for this will likely get pushed out tomorrow.  I will be checking myself to make sure it's fixed (and will follow up with them if it isn't).  Thanks!

 

Best Regards,
Shannon W.
API Support Specialist

JudyP0
Occasional Participant

I realized that I Mashery says that they fixed this problem. Howerver, I am getting the same result:

 

[{"error_key":"json.payload.invalid","error_message":"Unable to parse JSON payload."}]

using this payload:

 

{"addresses": [],"lists": [{"id": "N"}],"cell_phone": "","company_name": "","confirmed": false,"email_addresses": [{"email_address":somebody@somewhere.com"}],"fax": "","first_name": "","home_phone": "","job_title": "","last_name": "","middle_name": "","prefix_name": "","work_phone": ""}

 

I am using https post in a script.

 

What is the minimum payload for adding a contact?

There is actually an error in your JSON, it's invalid (you can use a validator here to test out your JSON in the future).  The problem is a missing double quote in the value of the "email_address" field.  Correct JSON should be...

 

{
    "addresses": [],
    "lists": [
        {
            "id": "N"
        }
    ],
    "cell_phone": "",
    "company_name": "",
    "confirmed": false,
    "email_addresses": [
        {
            "email_address": "somebody@somewhere.com"
        }
    ],
    "fax": "",
    "first_name": "",
    "home_phone": "",
    "job_title": "",
    "last_name": "",
    "middle_name": "",
    "prefix_name": "",
    "work_phone": ""
}

Dave Berard
Senior Product Manager, Constant Contact
JudyP0
Occasional Participant

Thanks Dave.

 

That is embarrassig. Actually, I deleted that quotation mark when I was changing the email address in the post. Still, good idea to validate.

 

I corrected the JSON (ran through a validator):

{
"addresses": [],
"lists": [
{
"id": "N"
}
],
"cell_phone": "",
"company_name": "",
"confirmed": "false",
"email_addresses": [
{
"email_address": "somebody@somewhere.com"
}
],
"fax": "",
"first_name": "",
"home_phone": "",
"job_title": "",
"last_name": "",
"middle_name": "",
"prefix_name": "",
"work_phone": ""
}

 

Still not working:

 

[{"error_key":"json.payload.invalid","error_message":"Unable to parse JSON payload."}]

 

My understanding is that both the api_key and action_by values are part of the query set. Right?

 

 

You're correct, those are used as part of the URL as query parameters.  I was able to use your JSON and get a different error message (confirmed field is not supported on a post).  Here is the URI and payload I used that did create a Contact (access_token is purposely redacted) in a REST client to do a POST:

 

URI: https://api.constantcontact.com/v2/contacts?api_key={api_key}&access_token={access_token}

Verb: POST

Payload:

 

{
"addresses": [],
"lists": [
{
"id": "1"
}
],
"cell_phone": "",
"company_name": "",
"email_addresses": [
{
"email_address": "somebody@somewhere.com"
}
],
"fax": "",
"first_name": "",
"home_phone": "",
"job_title": "",
"last_name": "",
"middle_name": "",
"prefix_name": "",
"work_phone": ""
}

Dave Berard
Senior Product Manager, Constant Contact
JudyP0
Occasional Participant

Hi Dave,

 

I appreciate you walking me through this. 

 

Still not working. Same error message.

 

Just one last question and I will drop it.

 

Here are the values I am using:

 

j

jsonRequestBody:
{"addresses": [],"lists": [{"id": "2"}],"cell_phone": "","company_name": "","email_addresses": [{"email_address": "somebody@somewhere.com"}],"fax": "","first_name": "","home_phone": "","job_title": "","last_name": "","middle_name": "","prefix_name": "","work_phone": ""}

 

request headers:

Authorization {Bearer access_token}

X-Originating-Ip 00.00.00.00

Content-Type application/json

 

query content

jsonRequestBody jsonRequestBody

Action-By ACTION_BY_OWNER (tried both in request headers and query content - no difference)

api_key api_key

access_token access_token

 

using an hppts POST

 

url: https://api.constantcontact.com/v2/contacts

 

Am I missing something?

 

Thanks.

Hi Judy,

 

I did take the time to test your exact request JSON with my own account and it worked without any errors. Would it be possible to send the request with all of the details still included to webservices@constantcontact.com? At this point it's likely that the error is related to the specific content of the request.

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer

Judy,

I had this same exact problem and I was able to finally fix when I the body of the post with nothing but the json object. I did not add a "jsonRequestBody" key/label to the posting data.

 

In otherwords, just send
{"addresses": [],"lists": [{"id": "2"}],"cell_phone": "","company_name": "","email_addresses": [{"email_address": "somebody@somewhere.com"}],"fax": "","first_name": "","home_phone": "","job_title": "","last_name": "","middle_name": "","prefix_name": "","work_phone": ""}

 

Don't send it as
jsonRequestBody : {"addresses": [],"lists": [{"id": "2"}],"cell_phone": "","company_name": "","email_addresses": [{"email_address": "somebody@somewhere.com"}],"fax": "","first_name": "","home_phone": "","job_title": "","last_name": "","middle_name": "","prefix_name": "","work_phone": ""}

 

I hope this helps because I was stuck for a while on it and could not find any help online.

MAKM4
Regular Participant

Hi,

Please help in "There was a conflict between the supplied data and the existing resource" error.

I am using constant contact php-api and I am getting the above mentioned error, but it does not occur while creating a new contact while the same error occurs when I am updating a contact (when confirmed opt-in is on he has confirmed the subscription). Also I dont get any error whether it is adding a new contact or updating an existing contact while the Confirmed opt-in is not used. I have already checked the email problem its related to email duplication.Dont know what to do, Please help me.

 

Thanks,

MAK

Responded to a couple of your other posts.  While this is not related to the original topic, we did mentioned this defect in our May release notes: http://developer.constantcontact.com/docs/release-notes/may-2014-rel-notes.html.  We are working on a solution now and hope to have this fixed in an upcoming release.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page