Response Formats

Choose JSON or XML responses and understand request formats, XML structure, and error handling.

Choose JSON or XML responses for supported TextGrid resource endpoints, and use the correct request format independently of that choice.

Select the response format using the URL

For endpoints documented with paired JSON and XML routes:

URLSuccessful response
Ends in .jsonJSON
Same route without .jsonXML

For example, retrieve an account as JSON:

GET https://api.textgrid.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID.json
Authorization: Bearer YOUR_BASE64_ENCODED_CREDENTIALS

To retrieve the XML representation, omit the suffix:

GET https://api.textgrid.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID
Authorization: Bearer YOUR_BASE64_ENCODED_CREDENTIALS

The documented route selects the success representation. Do not rely on changing only the Accept header to switch between the paired representations. Keep .json at the end of the path, before any query string.

Supported resource operations

The paired routes documented in the API Reference cover:

  • Account retrieval, subaccount listing, creation, and updates.
  • Individual-message sending and retrieval, message listing, and message-media listing.
  • Outgoing-call creation, call retrieval, and call listing.
  • Available-number searches, phone-number purchase, listing, retrieval, and updates, and caller-ID registration.
  • Phone-number forwarding retrieval and the suffixless aliases for forwarding updates and number release. Forwarding updates and number release have no successful response body.

See each operation in the API Reference for its exact routes and response fields. The generated response schemas and request explorer document JSON. Each applicable success response links to its XML field reference below, including the suffixless URL for XML requests.

Request format is a separate choice

Removing .json selects the documented XML response route; it does not mean you should change the request body to XML.

Continue using the request format documented for that operation. For example:

OperationDocumented request format, including on the XML response route
Send a messageJSON
Create an outgoing callJSON
Purchase or update a phone numberForm fields
Update call forwardingJSON

Keep the same request field names and authentication. For instance, a message request still uses from, to, and body, and an outgoing call request still uses From, To, and Url.

Read XML using its own structure

XML responses use their own element names and structure, with resource elements such as Account, Message, or Call.

For example, JSON uses account_balance, while XML uses AccountBalance. The following is a partial illustration, not a complete account response:

<?xml version="1.0" encoding="UTF-8"?>
<TwilioResponse>
  <Account>
    <Sid>EXAMPLE_ACCOUNT_SID</Sid>
    <AccountBalance>125.50</AccountBalance>
  </Account>
</TwilioResponse>

List responses can place pagination information in XML attributes and return repeated resource elements. XML date fields use XML Schema dateTime serialization rather than the day/month display strings used in the JSON examples. Use the XML schema and example for the selected operation instead of deriving XML names or formats from the JSON response.

Null values

JSON response fields with null values are omitted. XML handling depends on the field: a value can be omitted or represented using an XML Schema-instance nil attribute.

For a null account balance, XML can contain:

<AccountBalance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />

The namespace prefix is not fixed. A response using p4:nil with the same namespace URI means the same thing as xsi:nil.

Exceptions to the suffix convention

Do not apply the rule to every TextGrid URL. In particular:

  • 10DLC registration and opt-in/out endpoints have their own documented routes; a suffixless route does not imply the TwilioResponse XML representation.
  • Phone-number lookups use their separate base URL and documented response format.
  • Email and bulk-message operations are documented separately. Do not assume bulk-message success responses use the same XML format as individual messages.
  • Webhook callback URLs belong to your application. Their GET/query, POST/form, or POST/JSON payload formats follow the webhook contract, not the presence of .json in your URL.
  • TwiML is the XML you return for supported call instructions or automatic message replies. It is separate from an API resource's XML response format.

Handle errors by their actual content

The suffix rule describes the documented resource success response. Error branches can return XML, JSON, or an empty body. Some translated resource errors contain a RestException element, while other failures use framework or application error responses.

Check the HTTP status and actual Content-Type before parsing an error, and allow an empty response body. See Troubleshooting Messages and Calls.

XML field reference

Use the suffixless routes below for XML responses. Field names are shown exactly as XML elements; names beginning with @ are attributes. The API Reference response panels document JSON fields.

XML Account

GET /Accounts/{accountSid}

POST /Accounts

POST /Accounts/{subAccountSid}

Fields inside <Account>.

FieldType
Statusstring
DateUpdatedstring
AuthTokenstring
FriendlyNamestring
OwnerAccountSidstring
Uristring
Sidstring
DateCreatedstring
Typestring
webhook_secretstring
AccountBalancenumber or null

XML Accounts

GET /Accounts

Fields inside <Accounts>.

FieldType
@endinteger
@firstpageuristring
@lastpageuristring
@nextpageuristring
@numpagesinteger
@pageinteger
@pagesizeinteger
@previouspageuristring
@startinteger
@totalinteger
@uristring
Accountarray
Account[].Statusstring
Account[].DateUpdatedstring
Account[].AuthTokenstring
Account[].FriendlyNamestring
Account[].OwnerAccountSidstring
Account[].Uristring
Account[].Sidstring
Account[].DateCreatedstring
Account[].Typestring
Account[].webhook_secretstring
Account[].AccountBalancenumber or null

XML Call

GET /Accounts/{accountSid}/Calls/{callSid}

Fields inside <Call>.

FieldType
Sidstring
DateCreatedstring
DateUpdatedstring
AccountSidstring
Statusstring
Durationinteger or null
ApiVersionstring
Pricestring
PriceUnitstring
Uristring
ParentCallSidstring
CallerNamestring
Fromstring
Tostring
Annotationstring
AnsweredBystring
QueueTimestring
Directionstring
StartTimestring
FromFormattedstring
GroupSidstring
TrunkSidstring
ForwardedFromstring
EndTimestring
ToFormattedstring
PhoneNumberSidstring
SubresourceUrisobject
SubresourceUris.Mediastring
DigitsPressedstring

XML Calls

GET /Accounts/{accountSid}/Calls

Fields inside <Calls>.

FieldType
@endinteger
@firstpageuristring
@lastpageuristring
@nextpageuristring
@numpagesinteger
@pageinteger
@pagesizeinteger
@previouspageuristring
@startinteger
@totalinteger
@uristring
Callarray
Call[].Sidstring
Call[].DateCreatedstring
Call[].DateUpdatedstring
Call[].AccountSidstring
Call[].Statusstring
Call[].Durationinteger or null
Call[].ApiVersionstring
Call[].Pricestring
Call[].PriceUnitstring
Call[].Uristring
Call[].ParentCallSidstring
Call[].CallerNamestring
Call[].Fromstring
Call[].Tostring
Call[].Annotationstring
Call[].AnsweredBystring
Call[].QueueTimestring
Call[].Directionstring
Call[].StartTimestring
Call[].FromFormattedstring
Call[].GroupSidstring
Call[].TrunkSidstring
Call[].ForwardedFromstring
Call[].EndTimestring
Call[].ToFormattedstring
Call[].PhoneNumberSidstring
Call[].SubresourceUrisobject
Call[].SubresourceUris.Mediastring

XML Call Initiate outbound call

POST /Accounts/{accountSid}/Calls

Fields inside <Call>.

FieldType
Sidstring
DateCreatedstring
DateUpdatedstring
AccountSidstring
Statusstring
Durationinteger or null
ApiVersionstring
Pricestring
PriceUnitstring
Uristring
ParentCallSidstring
CallerNamestring
Fromstring
Tostring
Annotationstring
AnsweredBystring
QueueTimestring
Directionstring
StartTimestring
FromFormattedstring
GroupSidstring
TrunkSidstring
ForwardedFromstring
EndTimestring
ToFormattedstring
PhoneNumberSidstring
SubresourceUrisobject
SubresourceUris.Mediastring

XML Message

POST /Accounts/{accountSid}/Messages

GET /Accounts/{accountSid}/Messages/{messageSid}

Fields inside <Message>.

FieldType
Bodystring
NumSegmentsstring
Directionstring
Fromstring
DateUpdatedstring
Pricestring
Surchargestring
ErrorMessagestring
Uristring
AccountSidstring
NumMediastring
NumImagesstring
Tostring
DateCreatedstring
Statusstring
Sidstring
DateSentstring
MessagingServiceSidstring
ErrorCodestring
PriceUnitstring
ApiVersionstring
Emailboolean
CarrierNetworkstring
MessageClassstring
SubresourceUrisobject
SubresourceUris.Mediastring

XML Messages

GET /Accounts/{accountSid}/Messages

Fields inside <Messages>.

FieldType
@endinteger
@firstpageuristring
@lastpageuristring
@nextpageuristring
@numpagesinteger
@pageinteger
@pagesizeinteger
@previouspageuristring
@startinteger
@totalinteger
@uristring
Messagearray
Message[].Bodystring
Message[].NumSegmentsstring
Message[].Directionstring
Message[].Fromstring
Message[].DateUpdatedstring
Message[].Pricestring
Message[].Surchargestring
Message[].ErrorMessagestring
Message[].Uristring
Message[].AccountSidstring
Message[].NumMediastring
Message[].NumImagesstring
Message[].Tostring
Message[].DateCreatedstring
Message[].Statusstring
Message[].Sidstring
Message[].DateSentstring
Message[].MessagingServiceSidstring
Message[].ErrorCodestring
Message[].PriceUnitstring
Message[].ApiVersionstring
Message[].Emailboolean
Message[].CarrierNetworkstring
Message[].MessageClassstring
Message[].SubresourceUrisobject
Message[].SubresourceUris.Mediastring

XML MediaList

GET /Accounts/{accountSid}/Messages/{messageSid}/Media

Fields inside <MediaList>.

FieldType
@endinteger
@firstpageuristring
@lastpageuristring
@nextpageuristring
@numpagesinteger
@pageinteger
@pagesizeinteger
@previouspageuristring
@startinteger
@totalinteger
@uristring
Mediasarray
Medias[].Sidstring
Medias[].DateCreatedstring
Medias[].DateUpdatedstring
Medias[].AccountSidstring
Medias[].ParentSidstring
Medias[].ContentTypestring
Medias[].Uristring

XML AvailablePhoneNumbers

GET /Accounts/{accountSid}/AvailablePhoneNumbers/{isoCountryCode}/Local

Fields inside <AvailablePhoneNumbers>.

FieldType
AvailablePhoneNumberarray
AvailablePhoneNumber[].FriendlyNamestring
AvailablePhoneNumber[].PhoneNumberstring
AvailablePhoneNumber[].Latastring
AvailablePhoneNumber[].RateCenterstring
AvailablePhoneNumber[].Regionstring
AvailablePhoneNumber[].IsoCountrystring
AvailablePhoneNumber[].Betaboolean
AvailablePhoneNumber[].Capabilitiesobject
AvailablePhoneNumber[].Capabilities.Voiceboolean
AvailablePhoneNumber[].Capabilities.OutgoingVoiceOnlyboolean
AvailablePhoneNumber[].Capabilities.SMSboolean
AvailablePhoneNumber[].Capabilities.OutgoingSMSOnlyboolean
AvailablePhoneNumber[].Capabilities.MMSboolean
@uristring
Capabilitiesobject
Capabilities.Voiceboolean
Capabilities.OutgoingVoiceOnlyboolean
Capabilities.SMSboolean
Capabilities.OutgoingSMSOnlyboolean
Capabilities.MMSboolean

XML IncomingPhoneNumber

POST /Accounts/{accountSid}/IncomingPhoneNumbers

POST /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}

GET /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}

POST /Accounts/{accountSid}/CallerID

Fields inside <IncomingPhoneNumber>.

FieldType
Sidstring
AccountSidstring
FriendlyNamestring
PhoneNumberstring
VoiceUrlstring
VoiceMethodstring
VoiceFallbackUrlstring
VoiceFallbackMethodstring
DateCreatedstring
DateUpdatedstring
SmsUrlstring
SmsMethodstring
SmsFallbackUrlstring
SmsFallbackMethodstring
Betaboolean
Capabilitiesobject
Capabilities.Voiceboolean
Capabilities.OutgoingVoiceOnlyboolean
Capabilities.SMSboolean
Capabilities.OutgoingSMSOnlyboolean
Capabilities.MMSboolean
StatusCallbackstring
StatusCallbackMethodstring
ApiVersionstring
Uristring
Statusstring
CampaignIDstring
CampaignNamestring
ConnectionStatusstring
GhlDefaultboolean

XML IncomingPhoneNumbers

GET /Accounts/{accountSid}/IncomingPhoneNumbers

Fields inside <IncomingPhoneNumbers>.

FieldType
@endinteger
@firstpageuristring
@lastpageuristring
@nextpageuristring
@numpagesinteger
@pageinteger
@pagesizeinteger
@previouspageuristring
@startinteger
@totalinteger
@uristring
IncomingPhoneNumberarray
IncomingPhoneNumber[].Sidstring
IncomingPhoneNumber[].AccountSidstring
IncomingPhoneNumber[].FriendlyNamestring
IncomingPhoneNumber[].PhoneNumberstring
IncomingPhoneNumber[].VoiceUrlstring
IncomingPhoneNumber[].VoiceMethodstring
IncomingPhoneNumber[].VoiceFallbackUrlstring
IncomingPhoneNumber[].VoiceFallbackMethodstring
IncomingPhoneNumber[].DateCreatedstring
IncomingPhoneNumber[].DateUpdatedstring
IncomingPhoneNumber[].SmsUrlstring
IncomingPhoneNumber[].SmsMethodstring
IncomingPhoneNumber[].SmsFallbackUrlstring
IncomingPhoneNumber[].SmsFallbackMethodstring
IncomingPhoneNumber[].Betaboolean
IncomingPhoneNumber[].Capabilitiesobject
IncomingPhoneNumber[].Capabilities.Voiceboolean
IncomingPhoneNumber[].Capabilities.OutgoingVoiceOnlyboolean
IncomingPhoneNumber[].Capabilities.SMSboolean
IncomingPhoneNumber[].Capabilities.OutgoingSMSOnlyboolean
IncomingPhoneNumber[].Capabilities.MMSboolean
IncomingPhoneNumber[].StatusCallbackstring
IncomingPhoneNumber[].StatusCallbackMethodstring
IncomingPhoneNumber[].ApiVersionstring
IncomingPhoneNumber[].Uristring
IncomingPhoneNumber[].Statusstring
IncomingPhoneNumber[].CampaignIDstring
IncomingPhoneNumber[].CampaignNamestring
IncomingPhoneNumber[].ConnectionStatusstring
IncomingPhoneNumber[].GhlDefaultboolean

XML NumberForward

GET /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}/forward

Fields inside <NumberForward>.

FieldType
forwardTostring
forwardEnabledboolean or null
forwardRecordboolean or null
ghlDefaultboolean or null

Did this page help you?