balanced / balanced-api

Balanced API specification.
221 stars 72 forks source link

improvement(api v1.1) - updating a customer with a null or empty email should not return a 400 Bad Request Error #516

Closed joeenzminger closed 10 years ago

joeenzminger commented 10 years ago

Currently, you get a Balanced Error "Invalid field [email]. "" must be a valid email address as specified by RFC-2822....

Since email isn't a required field, it shouldn't validate unless it is not null and has a non-zero length.

mjallday commented 10 years ago

In this case the field is not null however. The Balanced API differentiates between null and "". If you omit the email address from the request it will not be updated.

Passing null will explicitly set the value of the email field to null which is different from not passing it at all

curl https://api.balancedpayments.com/customers/CU3AYNOTGGyp9vWdy578Wcc0 -H "Accept: application/vnd.api+json;revision=1.1" -u ak-test-h7F8F3u41y6LzCK4nZeVd5BafaWOUuZL: -X PUT -H "Content-type: application/json" -d '{"email": null}'

{
  "customers": [
    {
      "name": "Henry Ford",
      "links": {
        "source": null,
        "destination": null
      },
      "updated_at": "2014-02-18T01:54:24.185443Z",
      "created_at": "2014-02-14T03:38:26.002760Z",
      "dob_month": 7,
      "id": "CU3AYNOTGGyp9vWdy578Wcc0",
      "phone": null,
      "href": "/customers/CU3AYNOTGGyp9vWdy578Wcc0",
      "merchant_status": "underwritten",
      "meta": {
        "shipping-preference": "ground"
      },
      "dob_year": 1963,
      "address": {
        "city": null,
        "line2": null,
        "line1": null,
        "state": null,
        "postal_code": "48120",
        "country_code": null
      },
      "business_name": null,
      "ssn_last4": null,
      "email": null,
      "ein": null
    }
  ],
  "links": {
    "customers.source": "/resources/{customers.source}",
    "customers.card_holds": "/customers/{customers.id}/card_holds",
    "customers.bank_accounts": "/customers/{customers.id}/bank_accounts",
    "customers.debits": "/customers/{customers.id}/debits",
    "customers.destination": "/resources/{customers.destination}",
    "customers.cards": "/customers/{customers.id}/cards",
    "customers.transactions": "/customers/{customers.id}/transactions",
    "customers.refunds": "/customers/{customers.id}/refunds",
    "customers.reversals": "/customers/{customers.id}/reversals",
    "customers.orders": "/customers/{customers.id}/orders",
    "customers.credits": "/customers/{customers.id}/credits"
  }
}