Create Contact API v2 "code": 400, "message": "For input string: \"\""

{
  "addresses": [
    {
      "country": "United States of America",
      "country_code": "USA",
      "field": "OTHER",
      "line1": "@{triggerBody()?['address']}",
      "line2": "",
      "locality": "@{triggerBody()?['city']}",
      "postal_code": "@{triggerBody()?['postalCode']}",
      "region": "@{triggerBody()?['state']}",
      "region_code": "",
      "zip_code": "@{triggerBody()?['postalCode']}",
      "zip_four": ""
    }
  ],
  "anniversary_date": "@{triggerBody()?['DE_Original_Hire_Date']}",
  "birth_date": "2000-@{triggerBody()?['DE_Birth_Month']}-@{triggerBody()?['DE_Birth_Day']}",
  "company": {
    "company_name": "",
    "id": ""
  },
  "contact_type": "",
  "custom_fields": [
    {
      "content": {},
      "id": "string"
    }
  ],
  "email_addresses": [
    {
      "email": "@{triggerBody()?['emailAddr']}",
      "field": "EMAIL1",
      "opt_in_reason": "New Hire"
    }
  ],
  "family_name": "@{triggerBody()?['last_name']}",
  "fax_numbers": [
    {
      "field": "FAX1",
      "number": "@{triggerBody()?['DE_Fax_or_eFax']}",
      "type": "Work"
    }
  ],
  "given_name": "@{triggerBody()?['first_name']}",
  "job_title": "@{triggerBody()?['title']}",
  "leadsource_id": "",
  "middle_name": "",
  "origin": {
    "ip_address": ""
  },
  "owner_id": "",
  "phone_numbers": [
    {
      "extension": "",
      "field": "PHONE1",
      "number": "@{triggerBody()?['phone_number']}",
      "type": "@{triggerBody()?['DE_Phone_Type']}"
    }
  ],
  "preferred_locale": "en_US",
  "preferred_name": "@{triggerBody()?['DE_Enc_Preferred_Name']}",
  "prefix": "",
  "referral_code": "",
  "social_accounts": [
    {
      "name": "unknown",
      "type": "FACEBOOK"
    }
  ],
  "source_type": "IMPORT",
  "spouse_name": "",
  "suffix": "",
  "time_zone": "",
  "utm_parameters": {
    "keap_source_id": "123456",
    "utm_campaign": "",
    "utm_content": "",
    "utm_medium": "",
    "utm_source": "",
    "utm_term": ""
  },
  "website": "@{triggerBody()?['DE_User_Profile_URL']}"
}

Any suggestions on this one? Pretty stumped as to what its picking up.

Here is the full response too:

{
  "code": 400,
  "message": "For input string: \"\"",
  "status": "Bad Request",
  "details": [
    {
      "domain": "General",
      "resource": ""
    }
  ]
}

Can you supply the actual rendered message as it is being sent to the API endpoint for a test record (so that there is no PII)? I’m seeing interpolation commands there, but that doesn’t help us to identify what is invalid, and I can’t test that locally to debug.

1 Like

Here you go

{
    "uri": "https://api.infusionsoft.com/crm/rest/v2/contacts",
    "method": "POST",
    "headers": {
        "Content-Type": "application/json",
        "X-Keap-API-Key": "KeapAK-XXXXXXXXXXXXX"
    },
    "body": {
        "addresses": [
            {
                "country": "United States of America",
                "country_code": "USA",
                "field": "OTHER",
                "line1": "1873 S. Bellaire St Suite 850",
                "line2": "",
                "locality": "Denver",
                "postal_code": "80222",
                "region": "CO",
                "region_code": "",
                "zip_code": "80222",
                "zip_four": ""
            }
        ],
        "anniversary_date": "2023-11-14",
        "birth_date": "2000-07-19",
        "company": {
            "company_name": "",
            "id": ""
        },
        "contact_type": "",
        "custom_fields": [
            {
                "content": {},
                "id": "string"
            }
        ],
        "email_addresses": [
            {
                "email": "xxxxxx@xxxxxx.com",
                "field": "EMAIL1",
                "opt_in_reason": "New Hire"
            }
        ],
        "family_name": "Lastname",
        "fax_numbers": [
            {
                "field": "FAX1",
                "number": "",
                "type": "Work"
            }
        ],
        "given_name": "FirstName",
        "job_title": "JOb Title",
        "leadsource_id": "",
        "middle_name": "",
        "origin": {
            "ip_address": ""
        },
        "owner_id": "",
        "phone_numbers": [
            {
                "extension": "",
                "field": "PHONE1",
                "number": "(800) 867-5309",
                "type": "Mobile"
            }
        ],
        "preferred_locale": "en_US",
        "preferred_name": "",
        "prefix": "",
        "referral_code": "",
        "social_accounts": [
            {
                "name": "unknown",
                "type": "FACEBOOK"
            }
        ],
        "source_type": "IMPORT",
        "spouse_name": "",
        "suffix": "",
        "time_zone": "",
        "utm_parameters": {
            "keap_source_id": "BranchEmployee",
            "utm_campaign": "",
            "utm_content": "",
            "utm_medium": "",
            "utm_source": "",
            "utm_term": ""
        },
        "website": ""
    }
}

I ran it though in debug mode and identified the culprit: the leadsource_id, owner_id, and the custom_fields ids (as references to other objects) being blank strings is causing it to choke. I can log a ticket to address that, but you shouldn’t be sending blank strings regardless unless it’s intentional to supply an empty value. JSON differentiates between null (not provided) and empty (blank but present) strings.

1 Like

Thank you for this direction! Greatly appreciate it!