Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Last active July 27, 2016 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpawluk/77ec3f245fb299f70291c9c180dfe008 to your computer and use it in GitHub Desktop.
Save dpawluk/77ec3f245fb299f70291c9c180dfe008 to your computer and use it in GitHub Desktop.
Further examples of how the change to validate phone numbers as E.164 compliant can will break

##Example: Creating a user when the phone number must be valid *See Documentation

SUCCESS:

URL:

POST /api/v2/users.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org", "phone": "+15551234567"}}'

RESPONSE: HTTP/1.1 201 Created

{
  "user": {
    "id": 1,
    "url": "https://{subdomain}.zendesk.com/api/v2/users/1.json",
    "name": "Roger Wilco",
    "email": "roge@example.org",
    "phone": "+15551234567"
  }
}

FAILURE

URL:

POST /api/v2/users.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org", "phone": "5551234567"}}'

RESPONSE: HTTP/1.1 422 Unprocessable Entity

{
  "error": "RecordInvalid",
  "description": "Record validation errors",
  "details": {
    "phone": {
      "description": "Phone 5551234567 is not properly formatted",
      "error": "InvalidFormat"
    }
  }
}

##Example: Creating a user when the phone number must be unique *Documentation

SUCCESS:

URL:

POST /api/v2/users.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org", "phone": "+15551234567"}}'

RESPONSE: HTTP/1.1 201 Created

{
  "user": {
    "id": 1,
    "url": "https://{subdomain}.zendesk.com/api/v2/users/1.json",
    "name": "Roger Wilco",
    "email": "roge@example.org",
    "phone": "+15551234567",
    "shared_phone_number": "false"
  }
}

SUCCESS:

URL:

POST /api/v2/users.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge2@example.org", "phone": "+15551234567"}}'

RESPONSE: HTTP/1.1 201 Created

{
  "user": {
    "id": 1,
    "url": "https://{subdomain}.zendesk.com/api/v2/users/1.json",
    "name": "Roger Wilco",
    "email": "roge@example.org",
    "phone": "+15551234567",
    "shared_phone_number": "true"
  }
}

##Example: Editing a phone number using the Users API *Documentation

####SUCCESS:

URL:

PUT /api/v2/users/1.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users/1.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org", "phone": "+15551234567"}}'

RESPONSE: HTTP/1.1 200 OK

{
  "user": {
    "id": 1,
    "url": "https://{subdomain}.zendesk.com/api/v2/users/1.json",
    "name": "Roger Wilco",
    "email": "roge@example.org",
    "phone": "+15551234567"
  }
}

FAILURE:

URL:

PUT /api/v2/users/1.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users/1.json -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org", "phone": "5551234567"}}'

RESPONSE: HTTP/1.1 422 Unprocessable Entity

{
  "error": "RecordInvalid",
  "description": "Record validation errors",
  "details": {
    "phone": {
      "description": "Phone 555-123-4567 is not properly formatted",
      "error": "InvalidFormat"
    }
  }
}

##Example: Editing a phone number using the User Identities API *Documentation

SUCCESS:

URL:

PUT api/v2/users/{user_id}/identities/{id}.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users/{user_id}/identities/{id}.json -H "Content-Type: application/json" -X PUT -d '{"identity": {"value": "+15551234567"}}'

RESPONSE: HTTP/1.1 200 OK

{
  "identity": {
    "url": "https://{subdomain}.zendesk.com/api/v2/users/1.json",
    "id": 1,
    "user_id": 1,
    "type": "phone_number",
    "value": "+15551234567",
    "verified": true,
    "primary": true
  }
}

FAILURE:

URL:

PUT api/v2/users/{user_id}/identities/{id}.json

REQUEST:

curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users/{user_id}/identities/{id}.json -H "Content-Type: application/json" -X PUT -d '{"identity": {"value": "5551234567"}}'

RESPONSE: HTTP/1.1 200 OK

{
  "error": "RecordInvalid",
  "description": "Record validation errors",
  "details": {
    "phone": {
      "description": "Phone 5551234567 is not properly formatted",
      "error": "InvalidFormat"
    }
  }
}
@alexbevziuk-okta
Copy link

alexbevziuk-okta commented Jul 27, 2016

Hi, I suppose phone section has contains array, same as another errors type, am I right ?

{
  "error": "RecordInvalid",
  "description": "Record validation errors",
  "details": {
    "email": [
      {
        "description": "Email: alex@gmail.com is already being used by another user",
        "error": "DuplicateValue"
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment