0

Our shop is running on Salesforce Commerce Cloud (former Demandware) so we use DemadwareScript/JavaScript and Pipelines in the Salesforce Commerce Cloud UX Studio Environment. The task that I am trying to accomplish is to update a contact in the Salesforce Marketing Cloud when a user changes their account details on our site, using the REST API. Marketing Cloud Documentation is very precise on how to do that: Update Contacts. My only problem is that when I send the request with the "Contact Object" as the request body, which looks like this:

contactObject = {
    "contactKey": args.email,
    "attributeSets": [{
        "name": "Email Addresses",
        "items": [{
            "values": [{
                "name": "Email Address",
                "value": args.email
            },
            {
                "name": "HTML Enabled",
                "value": true
            }]
        }]
    },
    {
        "name": "TestCC",
        "items": [{
            "values": [{
                "name": "email",
                "value": args.email
                },
                {
                "name": "lastname",
                "value": args.lastName
                },
                {
                "name": "firstname",
                "value": args.firstName
                },
                {
                "name": "gender",
                "value": args.gender
                },
                {
                "name": "customerno",
                "value": args.customerNo
            }]
        }]
    }]
};

I use PATCH http service to make the update, which gives me I get the ERROR response "400 Bad Request":

{
    "documentation": "code.docs.exacttarget.com/rest/errors/400",
    "errorcode": 0,
    "message": "Bad Request"
}

Needless to say I checked out the documentation mentioned in the response, which showed "Site can't be reached", probably because salesforce is moving the documentation elsewhere, so I turned to the REST API documentation on error handling which didn't help at all.

So far so good - my code just doesn't work, right? The peculiar thing is that it DOES WORK just fine with the POST http verb, and if I understand it correctly from the documentation there is no difference in the request between "create contact" and "update contact" besides the http verb. When I use POST I successfully create a contact in the Data Extension in Marketing Cloud and I get a normal OK response, but if I replace POST with PATCH it gives me a Bad Request Error.

EDIT: I omitted the second array and checked the variable, and I still get the same error. My request body looks like this:

{
   "contactKey":"myvalid@email.com",
   "attributeSets":[
      {
         "name":"Email Addresses",
         "items":[
            {
               "values":[
                  {
                     "name":"Email Address",
                     "value":"myvalid@email.com"
                  },
                  {
                     "name":"HTML Enabled",
                     "value":true
                  }
               ]
            }
         ]
      }
   ]
}
  • Very strange, I can't reproduce this. Can you try omitting the TestCC DE and its items array, for debugging purposes? Also, double check that the args.email variable is being populated in your PATCH request. – Eliot Harper May 17 '17 at 15:41
  • I omitted the second array and checked the variable, and I still get the same error. See post edit for the request body. – Pres May 18 '17 at 10:49
  • It has to be related to how your code is making PATCH requests, I can't think of any other logical explanation. Please can you try making the same request using Postman REST client and let me know if you have the same issue? – Eliot Harper May 18 '17 at 15:41
0

According to Eliot Harper's suggestion in the comments that the PATCH service was wrong, which was my suspicion as well, I tried the requests with Postman REST client and it gave me some clues when debugging my code and I was able to fix the PATCH service, which was making a POST request instead.

This issue is resolved, if you have problems with the request body object or the services, try the Postman REST client, it may help you gather more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.