3

Every request I make to SFMC's API for contact creation seems to result in a 500. I am following the documentation provided to us and I have included the example requests below. The only thing I could think of is that there is a bug or a permission issue. I can't fathom another reason to respond with a 500.

Note: I am focusing on the contact create/update (upsert if you will) call here and I have tried this same request with a real email and get the same 500 response. Also note that the link they provide in the response is dead smh :/

Attempt – Using /contacts/v1/contacts

Example request:

    Host: https://www.exacttargetapis.com
    POST /contacts/v1/contacts
    Content-Type: application/json
    Authorization: Bearer ${AUTH_TOKEN}

    {
      "contactKey": "local-97005",
      "attributeSets": [
        {
          "name": "Email Addresses",
          "items": [
            {
              "values": [
                {
                  "name": "Email Address",
                  "value": "sfmctest2@mailinator.com"
                }
              ]
            }
          ]
        }
      ]
    }

    Example response:

    HTTP 500
    {
      "message":"Internal Server Error",
      "errorcode":0,
      "documentation":"https://code.docs.exacttarget.com/rest/errors/500"
    }

cURL Request

    curl -X POST -H "Authorization: Bearer <token removed for posting>" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 5fd50d70-f8ec-814a-d01b-c15649d24681" -d '{
        "contactKey": "local-123452",
        "attributeSets": [{ 
            "name": "Email Addresses", 
                "items": [{
                    "values": [{
                        "name": "Email Address",
                        "value": "testmcapi@mailinator.com"
                    }]
                }]
        }]
    }' "https://www.exacttargetapis.com/contacts/v1/contacts"

EDIT:

Here are data access configurations for the token Data

Second EDIT

I tried adding HTML Enabled to the request as it is noted as a required field in the documentation, however, I now recieve a 400 Bad Request.

Request

curl -X POST -H "Authorization: Bearer <Token Omitted>" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 797d8be2-a14b-5b25-a620-25540a264de6" -d '{ "contactKey": "local-123456", "attributeSets": [{ "name": "Email Addresses", "items": [{ "values": [{ "name": "Email Address", "value": "sfmctest2@mailinator.com" },{ "name": "HTML Enabled", "value": true }] }] } ] }' "https://www.exacttargetapis.com/contacts/v1/contacts"

Response

  {
    "operationStatus": "FAIL",
    "rowsAffected": 0,
    "requestServiceMessageID": "cebddc10-69ab-4399-92b8-ced05df00a1b",
    "hasErrors": true,
    "resultMessages": [
      {
        "formatStringParams": [
          "ValueDefinition",
          null,
          null,
          "HTML Enabled"
        ],
        "messageFormatString": "Unable to resolve schema element of type: {0} by reference. [Id: {1}, Key: {2}, Name: {3}]",
        "resultType": "Validation",
        "resultClass": "Error",
        "resultCode": "SchemaObjectNotFoundByReference",
        "message": "Unable to resolve schema element of type: ValueDefinition by reference. [Id: , Key: , Name: HTML Enabled]"
      }
    ],
    "serviceMessageID": "075ac816-e226-4698-a969-e082efdcf5c0"
  }
  • How did you obtained the oauth token ? Also when you created the app using app development console did you provided ability to write/read into contacts – Mohith Shrivastava Feb 10 '17 at 17:26
  • Great question, I have gave the app all the possible read / write permissions allotted to me in the Data Access menu under appcenter.s1.marketingcloudapps.com Auth request: curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: f14929d3-c8eb-4ee4-3f49-59d553a751a8" -d '{ "clientId":"our-client-id", "clientSecret":"our-secret-here" }' "auth.exacttargetapis.com/v1/requestToken" It results in a successful response with a token { "accessToken": "sometoken", "expiresIn": 3479 } – Steven Gall Feb 10 '17 at 21:52
  • { "contactKey": "local-123456", "attributeSets": [{ "name": "Email Addresses", "items": [{ "values": [{ "name": "Email Address", "value": "msrivastav13@gmail.com" },{ "name": "HTML Enabled", "value": true }] }] } ] } – Mohith Shrivastava Feb 11 '17 at 1:03
  • I tried above and it worked for me . – Mohith Shrivastava Feb 11 '17 at 1:03
  • Hmmm, possible permissioning error then? I'll take a screenshot of what I have. – Steven Gall Feb 14 '17 at 0:15
4

As Mohith comments, HTML Enabled is a required attribute, however you shouldn't receive a 500 error. Here's a working request:

Host: https://www.exacttargetapis.com
POST /contacts/v1/contacts
Content-Type: application/json
Authorization: Bearer {{accessToken}}

{  
   "contactKey":"6dcb271e-06db-4100-bebb-b141469cd4d1",
   "attributeSets":[  
      {  
         "name":"Email Addresses",
         "items":[  
            {  
               "values":[  
                  {  
                     "name":"Email Address",
                     "value":"simon@sausage.com"
                  },
                  {  
                     "name":"HTML Enabled",
                     "value":true
                  }
               ]
            }
         ]
      }
   ]
}

This returns the response payload:

{
  "operationStatus": "OK",
  "rowsAffected": 1,
  "contactKey": "6dcb271e-06db-4100-bebb-b141469cd4d1",
  "contactID": 12345678,
  "contactTypeID": 0,
  "isNewContactKey": true,
  "requestServiceMessageID": "23ba75f2-ab1c-4b67-93dd-08de25f28c42",
  "hasErrors": false,
  "resultMessages": [],
  "serviceMessageID": "673451c6-ce6b-4329-b1bf-6e1e1664803e"
}

If you are still having issues, please double-check that you have Write permission enabled in Contacts > List And Subscribers in your app (in App Center).

| improve this answer | |
  • I added a screenshot of the app permissions and it looks like it has write permission on contacts and adding the HTML Enabled attribute to the request results in a 400 Bad Request due to the schema. I'm going to verify within SFMC that the attribute exists. (I would assume it does since it is a system field unless they provisioned our account incorrectly) – Steven Gall Feb 15 '17 at 16:15
  • @StevenGall that's very strange. If you connect with me we can setup a quick webinar session to review this. I'm sure it's something simple! – Eliot Harper Feb 15 '17 at 21:06
  • 1
    Eliot, it looks like there seems to be a problem with SFMC. We ponied up for Premier support and have posed the question to their developers. We got the following response. "I was able to replicate the API Responses which your team was receiving. I did not locate any errors within the Marketing Cloud, thus the case has been escalated to our senior analyst team." I'm going to accept your answer though since future folks may wonder how to create a contact and your response is indeed the way SFMC's API is intended to work – Steven Gall Feb 16 '17 at 16:30
0

I had the same problem and after a few days of trying to debug it I was able to get it to work. I also used the code above and it worked for me as well.

My solution was to create a new API Package under my Parent Business Unit and it worked immediately. The API Package I was originally working with was in a non-parent Business Unit even though I gave the parent Business Unit "Access" it still wouldn't work giving me the 400 Bad Request error.

I hope this helps anyone else who ran into this problem.

| improve this answer | |
0

Hi This error generally comes if it is new account and it does not have any Group Attributes or few of them are missing ex Email Data , Demographics . (Please check your Data Designer Tab if you can find any missing Group.

enter image description here

You need to ask support to provision it from back-end.

| improve this answer | |

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.