> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate and fetch MDR Usage Report

> Generate and fetch messaging usage report synchronously. This endpoint will both generate and fetch the messaging report over a specified time period. No polling is necessary but the response may take up to a couple of minutes. 



## OpenAPI

````yaml https://telnyx-openapi-ng.s3.us-east-1.amazonaws.com/account-billing/usage-reports.yml get /reports/mdr_usage_reports/sync
openapi: 3.1.0
info:
  title: Telnyx Usage Reports API
  version: 2.0.0
  description: API for Usage reports.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
security:
  - bearerAuth: []
paths:
  /reports/mdr_usage_reports/sync:
    get:
      tags:
        - MDR Usage Reports
      summary: Generate and fetch MDR Usage Report
      description: >-
        Generate and fetch messaging usage report synchronously. This endpoint
        will both generate and fetch the messaging report over a specified time
        period. No polling is necessary but the response may take up to a couple
        of minutes. 
      operationId: GetMDRUsageReportSync
      parameters:
        - name: start_date
          in: query
          schema:
            type: string
            format: date-time
            example: '2020-07-01T00:00:00-06:00'
        - name: end_date
          in: query
          schema:
            type: string
            format: date-time
            example: '2020-07-01T00:00:00-06:00'
        - name: aggregation_type
          in: query
          required: true
          schema:
            type: string
            example: PROFILE
            enum:
              - NO_AGGREGATION
              - PROFILE
              - TAGS
        - name: profiles
          in: query
          schema:
            type: array
            example:
              - My profile
            items:
              type: string
              example: My profile
      responses:
        '200':
          description: Successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MdrGetSyncUsageReportResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/reporting_ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            const response = await client.reports.mdrUsageReports.fetchSync({
            aggregation_type: 'PROFILE' });


            console.log(response.data);
        - lang: Python
          source: |-
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            response = client.reports.mdr_usage_reports.fetch_sync(
                aggregation_type="PROFILE",
            )
            print(response.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.Reports.MdrUsageReports.FetchSync(context.TODO(), telnyx.ReportMdrUsageReportFetchSyncParams{\n\t\tAggregationType: telnyx.ReportMdrUsageReportFetchSyncParamsAggregationTypeProfile,\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.reports.mdrusagereports.MdrUsageReportFetchSyncParams;

            import
            com.telnyx.sdk.models.reports.mdrusagereports.MdrUsageReportFetchSyncResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    MdrUsageReportFetchSyncParams params = MdrUsageReportFetchSyncParams.builder()
                        .aggregationType(MdrUsageReportFetchSyncParams.AggregationType.PROFILE)
                        .build();
                    MdrUsageReportFetchSyncResponse response = client.reports().mdrUsageReports().fetchSync(params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            response =
            telnyx.reports.mdr_usage_reports.fetch_sync(aggregation_type:
            :PROFILE)


            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->reports->mdrUsageReports->fetchSync(
                aggregationType: 'PROFILE',
                endDate: new \DateTimeImmutable('2020-07-01T00:00:00-06:00'),
                profiles: ['My profile'],
                startDate: new \DateTimeImmutable('2020-07-01T00:00:00-06:00'),
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx reports:mdr-usage-reports fetch-sync \
              --api-key 'My API Key' \
              --aggregation-type PROFILE
components:
  schemas:
    MdrGetSyncUsageReportResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/MdrUsageReportResponse'
    reporting_ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/reporting_Error'
    MdrUsageReportResponse:
      type: object
      properties:
        id:
          type: string
          description: Identifies the resource
          format: uuid
        start_date:
          type: string
          format: date-time
          example: '2020-07-01T00:00:00-06:00'
        end_date:
          type: string
          format: date-time
          example: '2020-07-01T00:00:00-06:00'
        connections:
          type: array
          items:
            type: integer
            format: int64
        aggregation_type:
          type: string
          enum:
            - NO_AGGREGATION
            - PROFILE
            - TAGS
        status:
          type: string
          enum:
            - PENDING
            - COMPLETE
            - FAILED
            - EXPIRED
        report_url:
          type: string
          example: http://portal.telnyx.com/downloads/report_name_8hvb45Gu.csv
        result:
          type: array
          items:
            $ref: '#/components/schemas/MdrUsageRecord'
        created_at:
          type: string
          format: date-time
          example: '2020-07-01T00:00:00-06:00'
        updated_at:
          type: string
          format: date-time
          example: '2020-07-01T00:00:00-06:00'
        profiles:
          type: string
          example: My profile
        record_type:
          type: string
          example: mdr_usage_report
    reporting_Error:
      type: object
      properties:
        code:
          type: string
          example: '10011'
        title:
          type: string
          example: Bad Request
        detail:
          type: string
          example: Invalid parameter value
    MdrUsageRecord:
      type: object
      properties:
        cost:
          type: string
          example: '0'
        direction:
          type: string
          example: outbound
        product:
          type: string
          example: outbound
        connection:
          type: string
          example: all
        received:
          type: string
          example: '0'
        delivered:
          type: string
          example: '0'
        currency:
          type: string
          example: USD
        parts:
          type: string
          example: '0'
        sent:
          type: string
          example: '0'
        profile_id:
          type: string
          example: All
        tags:
          type: string
          example: All
        message_type:
          type: string
          example: SMS
        tn_type:
          type: string
          example: TF
        carrier_passthrough_fee:
          type: string
          example: '0'
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````