4

In my instance of Marketing Cloud, our contact Key is a Person Contact ID from our Salesforce Service Cloud org. These values are 18 characters. When a person uses their mobile device to opt-in to SMS, a contact is created with their mobile phone number as the contact key (since their phone doesn't know their Person Contact ID). I am creating a process to fix these contacts, but I first need a way to get all the contacts with bad contact keys.

I am trying to use the /contacts/v1/attributes/search REST API, but there seems to be very poor documentation about the ConditionSet. Simply, I want to get all contacts where Contact.Contact Key Equals MobileConnect Demographics.Mobile Number.

{
    "request": {
        "attributes": [
            {
                "key": "MobileConnect Demographics.Mobile Number"
            },
            {
                "key": "Contact.Contact ID"
            },
            {
                "key": "Contact.Contact Key"
            }
            ]

    },
    "conditionSet": {
        "operator": "And",
        "conditionSets": [],
        "conditions": [{
            "attribute": {
                "key": "Contact.Contact Key"
            },
            "operator": "Equals",
            "value": {
                "items": ["MobileConnect Demographics.Mobile Number"],
                "isAttribute": true
            }
        }]
    }
}

Unfortunately, I get the following error when I try this:

{
    "page": 0,
    "pageSize": 0,
    "count": 0,
    "links": {},
    "requestServiceMessageID": "743ff7a8-874e-47ac-9be3-de924cf4a323",
    "resultMessages": [
        {
            "resultType": "Validation",
            "resultClass": "Error",
            "resultCode": "InvalidAttribute",
            "message": "Data Type 'Phone' for Referenced Attribute 'Mobile Number' in Value for Attribute 'Contact Key' must be Text."
        },
        {
            "resultType": "Validation",
            "resultClass": "Error",
            "resultCode": "ValueNotAllowed",
            "message": "Value 'null' used for Attribute with DefinitionID 'd94f7d4d-dbe3-e611-9fee-00110a67f371' is not valid for Data Type 'Text' and Operator 'Equal'."
        }
    ],
    "serviceMessageID": "16c874c4-f5f6-45b1-b990-47bf1bcf4d82"
}

Any ideas or thoughts on how to solve this? I've tried a number of alternates and none seem to work.

3
  • You can't update contact keys. This is going to be very troublesome for your use case
    – 0xsegfault
    Commented Aug 4, 2017 at 15:04
  • You would have to delete it and possibly republish it
    – 0xsegfault
    Commented Aug 4, 2017 at 15:06
  • Frustrating that there's no additional documentation on ConditionSet. Commented Aug 4, 2017 at 17:18

1 Answer 1

4

If you do a GET on /contacts/v1/rest you can get a list of all of the methods. One of which is dataTypes, so if you do a GET on /contacts/v1/dataTypes, you'll have a list of available operators.

So if you can assume that Contact Keys that are phone numbers start with 1, you can use this POST to /contacts/v1/attributes/search:

{
    "request": {
        "attributes": [
            {
                "key": "MobileConnect Demographics.Mobile Number"
            },
            {
                "key": "Contact.Contact ID"
            },
            {
                "key": "Contact.Contact Key"
            }
            ]

    },
    "conditionSet": {
        "operator": "And",
        "conditionSets": [],
        "conditions": [{
            "attribute": {
                "key": "Contact.Contact Key"
            },
            "operator": "Begins",
            "value": {
                "items": ["1"]
            }
        },
        {
            "attribute": {
                "key": "MobileConnect Demographics.Mobile Number"
            },
            "operator": "IsNotNull",
            "value": {}
        }]
    }
}

I found the /contacts/v1/rest example in the SFMC Postman collection on Github.

1
  • Thanks for the Github link @Adam - you just made my day. Commented Jul 10, 2018 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .