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:
| URL | Successful response |
|---|---|
Ends in .json | JSON |
Same route without .json | XML |
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_CREDENTIALSTo retrieve the XML representation, omit the suffix:
GET https://api.textgrid.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID
Authorization: Bearer YOUR_BASE64_ENCODED_CREDENTIALSThe 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:
| Operation | Documented request format, including on the XML response route |
|---|---|
| Send a message | JSON |
| Create an outgoing call | JSON |
| Purchase or update a phone number | Form fields |
| Update call forwarding | JSON |
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
.jsonin 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>.
| Field | Type |
|---|---|
Status | string |
DateUpdated | string |
AuthToken | string |
FriendlyName | string |
OwnerAccountSid | string |
Uri | string |
Sid | string |
DateCreated | string |
Type | string |
webhook_secret | string |
AccountBalance | number or null |
XML Accounts
GET /Accounts
Fields inside <Accounts>.
| Field | Type |
|---|---|
@end | integer |
@firstpageuri | string |
@lastpageuri | string |
@nextpageuri | string |
@numpages | integer |
@page | integer |
@pagesize | integer |
@previouspageuri | string |
@start | integer |
@total | integer |
@uri | string |
Account | array |
Account[].Status | string |
Account[].DateUpdated | string |
Account[].AuthToken | string |
Account[].FriendlyName | string |
Account[].OwnerAccountSid | string |
Account[].Uri | string |
Account[].Sid | string |
Account[].DateCreated | string |
Account[].Type | string |
Account[].webhook_secret | string |
Account[].AccountBalance | number or null |
XML Call
GET /Accounts/{accountSid}/Calls/{callSid}
Fields inside <Call>.
| Field | Type |
|---|---|
Sid | string |
DateCreated | string |
DateUpdated | string |
AccountSid | string |
Status | string |
Duration | integer or null |
ApiVersion | string |
Price | string |
PriceUnit | string |
Uri | string |
ParentCallSid | string |
CallerName | string |
From | string |
To | string |
Annotation | string |
AnsweredBy | string |
QueueTime | string |
Direction | string |
StartTime | string |
FromFormatted | string |
GroupSid | string |
TrunkSid | string |
ForwardedFrom | string |
EndTime | string |
ToFormatted | string |
PhoneNumberSid | string |
SubresourceUris | object |
SubresourceUris.Media | string |
DigitsPressed | string |
XML Calls
GET /Accounts/{accountSid}/Calls
Fields inside <Calls>.
| Field | Type |
|---|---|
@end | integer |
@firstpageuri | string |
@lastpageuri | string |
@nextpageuri | string |
@numpages | integer |
@page | integer |
@pagesize | integer |
@previouspageuri | string |
@start | integer |
@total | integer |
@uri | string |
Call | array |
Call[].Sid | string |
Call[].DateCreated | string |
Call[].DateUpdated | string |
Call[].AccountSid | string |
Call[].Status | string |
Call[].Duration | integer or null |
Call[].ApiVersion | string |
Call[].Price | string |
Call[].PriceUnit | string |
Call[].Uri | string |
Call[].ParentCallSid | string |
Call[].CallerName | string |
Call[].From | string |
Call[].To | string |
Call[].Annotation | string |
Call[].AnsweredBy | string |
Call[].QueueTime | string |
Call[].Direction | string |
Call[].StartTime | string |
Call[].FromFormatted | string |
Call[].GroupSid | string |
Call[].TrunkSid | string |
Call[].ForwardedFrom | string |
Call[].EndTime | string |
Call[].ToFormatted | string |
Call[].PhoneNumberSid | string |
Call[].SubresourceUris | object |
Call[].SubresourceUris.Media | string |
XML Call Initiate outbound call
POST /Accounts/{accountSid}/Calls
Fields inside <Call>.
| Field | Type |
|---|---|
Sid | string |
DateCreated | string |
DateUpdated | string |
AccountSid | string |
Status | string |
Duration | integer or null |
ApiVersion | string |
Price | string |
PriceUnit | string |
Uri | string |
ParentCallSid | string |
CallerName | string |
From | string |
To | string |
Annotation | string |
AnsweredBy | string |
QueueTime | string |
Direction | string |
StartTime | string |
FromFormatted | string |
GroupSid | string |
TrunkSid | string |
ForwardedFrom | string |
EndTime | string |
ToFormatted | string |
PhoneNumberSid | string |
SubresourceUris | object |
SubresourceUris.Media | string |
XML Message
POST /Accounts/{accountSid}/Messages
GET /Accounts/{accountSid}/Messages/{messageSid}
Fields inside <Message>.
| Field | Type |
|---|---|
Body | string |
NumSegments | string |
Direction | string |
From | string |
DateUpdated | string |
Price | string |
Surcharge | string |
ErrorMessage | string |
Uri | string |
AccountSid | string |
NumMedia | string |
NumImages | string |
To | string |
DateCreated | string |
Status | string |
Sid | string |
DateSent | string |
MessagingServiceSid | string |
ErrorCode | string |
PriceUnit | string |
ApiVersion | string |
Email | boolean |
CarrierNetwork | string |
MessageClass | string |
SubresourceUris | object |
SubresourceUris.Media | string |
XML Messages
GET /Accounts/{accountSid}/Messages
Fields inside <Messages>.
| Field | Type |
|---|---|
@end | integer |
@firstpageuri | string |
@lastpageuri | string |
@nextpageuri | string |
@numpages | integer |
@page | integer |
@pagesize | integer |
@previouspageuri | string |
@start | integer |
@total | integer |
@uri | string |
Message | array |
Message[].Body | string |
Message[].NumSegments | string |
Message[].Direction | string |
Message[].From | string |
Message[].DateUpdated | string |
Message[].Price | string |
Message[].Surcharge | string |
Message[].ErrorMessage | string |
Message[].Uri | string |
Message[].AccountSid | string |
Message[].NumMedia | string |
Message[].NumImages | string |
Message[].To | string |
Message[].DateCreated | string |
Message[].Status | string |
Message[].Sid | string |
Message[].DateSent | string |
Message[].MessagingServiceSid | string |
Message[].ErrorCode | string |
Message[].PriceUnit | string |
Message[].ApiVersion | string |
Message[].Email | boolean |
Message[].CarrierNetwork | string |
Message[].MessageClass | string |
Message[].SubresourceUris | object |
Message[].SubresourceUris.Media | string |
XML MediaList
GET /Accounts/{accountSid}/Messages/{messageSid}/Media
Fields inside <MediaList>.
| Field | Type |
|---|---|
@end | integer |
@firstpageuri | string |
@lastpageuri | string |
@nextpageuri | string |
@numpages | integer |
@page | integer |
@pagesize | integer |
@previouspageuri | string |
@start | integer |
@total | integer |
@uri | string |
Medias | array |
Medias[].Sid | string |
Medias[].DateCreated | string |
Medias[].DateUpdated | string |
Medias[].AccountSid | string |
Medias[].ParentSid | string |
Medias[].ContentType | string |
Medias[].Uri | string |
XML AvailablePhoneNumbers
GET /Accounts/{accountSid}/AvailablePhoneNumbers/{isoCountryCode}/Local
Fields inside <AvailablePhoneNumbers>.
| Field | Type |
|---|---|
AvailablePhoneNumber | array |
AvailablePhoneNumber[].FriendlyName | string |
AvailablePhoneNumber[].PhoneNumber | string |
AvailablePhoneNumber[].Lata | string |
AvailablePhoneNumber[].RateCenter | string |
AvailablePhoneNumber[].Region | string |
AvailablePhoneNumber[].IsoCountry | string |
AvailablePhoneNumber[].Beta | boolean |
AvailablePhoneNumber[].Capabilities | object |
AvailablePhoneNumber[].Capabilities.Voice | boolean |
AvailablePhoneNumber[].Capabilities.OutgoingVoiceOnly | boolean |
AvailablePhoneNumber[].Capabilities.SMS | boolean |
AvailablePhoneNumber[].Capabilities.OutgoingSMSOnly | boolean |
AvailablePhoneNumber[].Capabilities.MMS | boolean |
@uri | string |
Capabilities | object |
Capabilities.Voice | boolean |
Capabilities.OutgoingVoiceOnly | boolean |
Capabilities.SMS | boolean |
Capabilities.OutgoingSMSOnly | boolean |
Capabilities.MMS | boolean |
XML IncomingPhoneNumber
POST /Accounts/{accountSid}/IncomingPhoneNumbers
POST /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}
GET /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}
POST /Accounts/{accountSid}/CallerID
Fields inside <IncomingPhoneNumber>.
| Field | Type |
|---|---|
Sid | string |
AccountSid | string |
FriendlyName | string |
PhoneNumber | string |
VoiceUrl | string |
VoiceMethod | string |
VoiceFallbackUrl | string |
VoiceFallbackMethod | string |
DateCreated | string |
DateUpdated | string |
SmsUrl | string |
SmsMethod | string |
SmsFallbackUrl | string |
SmsFallbackMethod | string |
Beta | boolean |
Capabilities | object |
Capabilities.Voice | boolean |
Capabilities.OutgoingVoiceOnly | boolean |
Capabilities.SMS | boolean |
Capabilities.OutgoingSMSOnly | boolean |
Capabilities.MMS | boolean |
StatusCallback | string |
StatusCallbackMethod | string |
ApiVersion | string |
Uri | string |
Status | string |
CampaignID | string |
CampaignName | string |
ConnectionStatus | string |
GhlDefault | boolean |
XML IncomingPhoneNumbers
GET /Accounts/{accountSid}/IncomingPhoneNumbers
Fields inside <IncomingPhoneNumbers>.
| Field | Type |
|---|---|
@end | integer |
@firstpageuri | string |
@lastpageuri | string |
@nextpageuri | string |
@numpages | integer |
@page | integer |
@pagesize | integer |
@previouspageuri | string |
@start | integer |
@total | integer |
@uri | string |
IncomingPhoneNumber | array |
IncomingPhoneNumber[].Sid | string |
IncomingPhoneNumber[].AccountSid | string |
IncomingPhoneNumber[].FriendlyName | string |
IncomingPhoneNumber[].PhoneNumber | string |
IncomingPhoneNumber[].VoiceUrl | string |
IncomingPhoneNumber[].VoiceMethod | string |
IncomingPhoneNumber[].VoiceFallbackUrl | string |
IncomingPhoneNumber[].VoiceFallbackMethod | string |
IncomingPhoneNumber[].DateCreated | string |
IncomingPhoneNumber[].DateUpdated | string |
IncomingPhoneNumber[].SmsUrl | string |
IncomingPhoneNumber[].SmsMethod | string |
IncomingPhoneNumber[].SmsFallbackUrl | string |
IncomingPhoneNumber[].SmsFallbackMethod | string |
IncomingPhoneNumber[].Beta | boolean |
IncomingPhoneNumber[].Capabilities | object |
IncomingPhoneNumber[].Capabilities.Voice | boolean |
IncomingPhoneNumber[].Capabilities.OutgoingVoiceOnly | boolean |
IncomingPhoneNumber[].Capabilities.SMS | boolean |
IncomingPhoneNumber[].Capabilities.OutgoingSMSOnly | boolean |
IncomingPhoneNumber[].Capabilities.MMS | boolean |
IncomingPhoneNumber[].StatusCallback | string |
IncomingPhoneNumber[].StatusCallbackMethod | string |
IncomingPhoneNumber[].ApiVersion | string |
IncomingPhoneNumber[].Uri | string |
IncomingPhoneNumber[].Status | string |
IncomingPhoneNumber[].CampaignID | string |
IncomingPhoneNumber[].CampaignName | string |
IncomingPhoneNumber[].ConnectionStatus | string |
IncomingPhoneNumber[].GhlDefault | boolean |
XML NumberForward
GET /Accounts/{accountSid}/IncomingPhoneNumbers/{phoneNumberSid}/forward
Fields inside <NumberForward>.
| Field | Type |
|---|---|
forwardTo | string |
forwardEnabled | boolean or null |
forwardRecord | boolean or null |
ghlDefault | boolean or null |
Updated 15 days ago