Get CDR Records
Overview
Get call (and messaging) delivery records from your account.
Authentication
Endpoint
POST https://api.portal.tsgglobal.world/graphql
Method
After sending messages or creating calls, you can check those by using the cdrRecords query which returns a paginatedCdrResult object type. This query is a bit more complex due to the usage of advanced GraphQL features like fragments and cursor based pagination.
Arguments which can be sent are listed below. The exclamation mark (!)means a parameter is mandatory, otherwise it's optional:
companyId: ID
For which company to list CDRs (only for admin users)
type: CdrType!
The type of the CDR records to list
startDatetime: DateTime!
Will return all records with datetime >= startDatetime
endDatetime: DateTime!
Will return all records with datetime < endDatetime (UTC based), max value is now
cursor: String
Used to paginate, returns results for the passed cursor (if any)
limit: Int
Limit the number of results per page, default is 100, max is 1000Sample Query
In this query GraphQL fragments are used (e.g. ... on MessageCdr { ... }, they are needed because what we return is a union of types for cdrs, and the fields are depending on the passed type. In our example below we're using SMS, but the fragments can be specified for each field in a general query, only change the type.
In our case the type is SMS, you send it as an uppercase string, example of variables sent:
Sample Variables
Sample Response
Pagination
We're using pagination for this endpoint because there can be milions of records for short time frames. To paginate through the results tweak the previous query so it looks like this (notice the new $limit and $cursor arguments):
query($type: CdrType!, $startDatetime: DateTime!, $endDatetime: DateTime!, $companyId: ID, $limit: Int, $cursor: String) { cdrRecords(type: $type, startDatetime: $startDatetime, endDatetime: $endDatetime, companyId: $companyId, limit: $limit, cursor: $cursor) {
and variables (limit=2 and cursor=null):
The results we get have paginationInfo filled differently, notice the limit and nextCursor properties below:
We need to use the nextCursor value to get the next page, the variables now look like the following:
This will get us the next round of results with another nextCursor value:
We can paginate until the result we get has nextCursor: null, when it's null it means we reached the end.
Exporting CDRs
You can export CDRs by using the exportLink which the cdrRecords query provides. The easiest way is to click on the link, but you can also do a server-side or client-side download if you want to save the results.
The links in the above example won't work since they're fake but you can generate one with your queries. The export will trigger a CSV file download (via HTTP streams) and include the fields you specified in the query, but the pagination options will be ignored.
Example of an export Link:
Notes
The export link is protected by a signature and cannot be tampered with, once generated it's public.
The export process has a timeout of 20 minutes, so if you notice the export timing out reduce the startDatetime and endDatetime period to something manageable and try again
Last updated
Was this helpful?