API Traffic Logs

Obtain request/response logs and payloads.

Obtain request logs

There are two queries that can be used to obtain request logs. The first (requestLogsByEntity) is used to obtain logs similar to what the API consumer sees in the Developer Dashboard (Apps), and the second (apiTrafficAnalyticsLogs) is used to obtain logs similar to what the API provider sees in Studio.

requestLogsByEntity

This query is used to obtain API usage analytics like those shown on the Analytics tab in the Developer Dashboard (Apps). This query can be used to obtain a collection of API request log information for one or more APIs or apps. The query can be filtered by date, API, app, HTTP response, etc.

2941

The requestLogsByEntity query is used to display logs in the Developer Dashboard (Apps).

Specify the API ID, app (projectId), fromDate, toDate, offset, limit, etc. in the Variables, as shown below in the two Variables tabs.

query RequestLogsByEntity($fromDate: String!, $toDate: String, $offset: Int, $limit: Int, $orderBy: RequestLogsOrderBy, $orderDir: OrderDirection, $filters: RequestLogFilters, $timeOffset: Int) {
  requestLogsByEntity(
    fromDate: $fromDate
    toDate: $toDate
    offset: $offset
    limit: $limit
    orderBy: $orderBy
    orderDir: $orderDir
    filters: $filters
    timeOffset: $timeOffset
  ) {
    requests {
      requestId
      endpoint
      httpMethod
      apiLatency
      callTime
      displayCallTime
      originCountry
      httpStatus
      apiId
      version {
        id
        name
      }
      project {
        name
        acl {
          entity {
            name
            email
            thumbnail
          }
        }
      }
    }
    totalCount
  }
}
{
  "filters": {
    "apiIds": [
      "api_6024cb01-90f9-4e84-a756-3768a35808da"
    ]
  },
  "fromDate": "2023-01-10T19:48:15.350Z",
  "toDate": "2023-01-17T19:48:15.350Z",
  "offset": 10,
  "limit": 10,
  "timeOffset": 0,
  "orderBy": "callTime",
  "orderDir": "desc"
}
{
  "projectId": "61784bcd6deb162134b9659d",
  "fromDate": "2024-03-16T00:00:00.000Z",
  "toDate": "2024-04-15T20:39:38.206Z",
  "offset": 0,
  "limit": 10,
  "orderBy": "callTime",
  "orderDir": "desc",
  "filters": {
    "projectIds": [
      "61784bcd6deb162134b9659d"
    ]
  },
  "showDeleted": true,
  "timeOffset": 0
}

apiTrafficAnalyticsLogs

Use the apiTrafficAnalyticsLogs query to obtain a collection of API request log information for one or more APIs or apps. The query can be filtered by date, API, app, HTTP response, etc. (see the where table below). This query uses Pagination (GQL) to return the results.

This query is used to display the list of logs that an API provider would see when they click on the Analytics tab in Studio (see screenshot below).

The list of recent logs for an API, shown on the Analytics tab in Studio.

The list of recent logs for an API, shown on the Analytics tab in Studio.

query apiTrafficAnalyticsLogs(
  $where: AnalyticsStatsLogsInput!
  $orderBy: [AnalyticsStatsLogsSortingInput!]
  $pagination: PaginationInput
) {
  apiTrafficAnalyticsLogs(
    where: $where
    orderBy: $orderBy
    pagination: $pagination
  ) {
    totalCount
    nodes {
      requestId
      consumer {
        name
        username
        slugifiedName
        thumbnail
        email
        __typename
      }
      endpointRoute
      endpointId
      httpMethod
      apiLatency
      callTime
      callTimeUTC
      originCountryName
      httpStatus
      apiVersionName
      isPayloadExist
      __typename
    }
    __typename
  }
}
{
  "where": {
    "apiIds": [
      "api_28f03d6e-955e-4f13-bed8-f574ff7530a2"
    ],
    "fromDate": "2024-03-23T07:00:00.000Z",
    "toDate": "2024-03-30T22:46:09.121Z",
    "timeOffset": 0
  },
  "orderBy": [
    {
      "by": "DESC",
      "fieldName": "DATE_TIME"
    }
  ],
  "pagination": {
    "first": 10,
    "after": ""
  }
}
{
  "data": {
    "apiTrafficAnalyticsLogs": {
      "totalCount": 152,
      "nodes": [
        {
          "requestId": "8c3d64b72726fe465d833a5c189e1d7401408690ecb8769c2518daddeacc6486",
          "consumer": {
            "name": "auser",
            "username": null,
            "slugifiedName": "auser",
            "thumbnail": "https://s3.amazonaws.com/rapidapi-prod-user/d5a69b00-1eee-44b4-b33d-446e987d3c7b",
            "email": "[email protected]",
            "__typename": "Entity"
          },

          "endpointRoute": "",
          "endpointId": "apiendpoint_37adc863-e838-45d5-ae73-d87007fcac93",
          "httpMethod": "POST",
          "apiLatency": 318,
          "callTime": "2024-03-29T22:54:33.000Z",
          "callTimeUTC": "2024-03-29T22:54:33.000Z",
          "originCountryName": "United States",
          "httpStatus": 200,
          "apiVersionName": "v1",
          "isPayloadExist": true,
          "__typename": "AnalyticsStatsLog"
        },
        {
          "requestId": "0b34862b2717dfb663cff703a81ce9fea548426727866907ab64e262e950c5e8",
          "consumer": {
            "name": "auser",
            "username": null,
            "slugifiedName": "auser",
            "thumbnail": "https://s3.amazonaws.com/rapidapi-prod-user/d5a69b00-1eee-44b4-b33d-446e987d3c7b",
            "email": "[email protected]",
            "__typename": "Entity"
          },

          "endpointRoute": "",
          "endpointId": "apiendpoint_37adc863-e838-45d5-ae73-d87007fcac93",
          "httpMethod": "POST",
          "apiLatency": 272,
          "callTime": "2024-03-29T13:50:57.000Z",
          "callTimeUTC": "2024-03-29T13:50:57.000Z",
          "originCountryName": "United States",
          "httpStatus": 200,
          "apiVersionName": "v1",
          "isPayloadExist": true,
          "__typename": "AnalyticsStatsLog"
        }
      ],

      "__typename": "AnalyticsStatsLogsConnection"
    }
  }
}

The following where variables of type AnalyticsStatsLogsInput are supported. Many of these are used to filter the results for specific conditions.

NameTypeRequiredExample
fromDateDateTimeYes"2024-03-21", "2024-03-21T07:00:00.000Z"
toDateDateTimeYes"2024-03-29", "2024-03-29T00:31:35.920Z"
timeOffsetIntNo0
apiIds[ID]No (default is all APIs)["api_04849dbb-4515-4dd3-899e-420e9af8076d",
"api_05433514-c272-4a59-a4f1-6cd281032c1a"]
projectIds (apps)[ID]No (default is all projectIds)[โ€œ62c43f324ce2d82497981553โ€] For details on obtaining this value, see this page. The default means that calls from all apps by all consumers will be included, returning data for all calls made to the API(s) during the period (useful for API providers and admins).
consumerIds[ID]No (default is all consumerIds)"consumerIds": [ "6028339" ] (user or team IDs)
endpointRoutes[String]No (default is all endpointRoutes)["apiendpoint_e564e317-3183-48a2-b02f-abeafc465d7bโ€] For details on obtaining this value, see this page. [] represents all endpoints.
endpointHashes[ID]No (default is all endpointHashes)
gatewayIds[ID]No (default is all gatewayIds)
apiVersionIds[ID]No (default is all apiVersionIds)[ "apiversion_675afc63-3ba3-40b8-8b3e-4e972b5f254a" ]
httpMethods[String]No (default is all httpMethods)[ "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD" ]
httpResponses[AnalyticsStatsHttpResponseInput]No (default is all httpResponses)[ { "ge": 200, "lt": 300 } ] (only includes 2XX responses)
originCountryNames[String]No (default is all originCountryNames)[ "unknown country" ]

Obtain request payload

Use the logPayloadByRequestIdWithLoggingRestrictions query to obtain request/response details similar to what an API provider would see when they click on an individual log on the Analytics tab in Studio (see screenshot below). This query requires the requestId, callTime, and apiId values that are returned from the apiTrafficAnalyticsLogs query above.

Viewing the request payload by clicking on a log in Studio.

Viewing the request payload by clicking on a log in Studio.

query Payload($requestId: ID, $apiId: String, $callTime: String!) {
  logPayloadByRequestIdWithLoggingRestrictions(
    requestId: $requestId
    callTime: $callTime
    apiId: $apiId
  ) {
    reqparams
    reqheaders
    resheaders
    reqbody
    resbody
    saveRequestQueryParametersLogging
    saveRequestHeadersLogging
    saveResponseHeadersLogging
    saveRequestBodyLogging
    saveResponseBodyLogging
    __typename
  }
}
{
  "requestId": "8c3d64b72726fe465d833a5c189e1d7401408690ecb8769c2518daddeacc6486",
  "callTime": "Fri, 29 Mar 2024 22:54:33 GMT",
  "apiId": "api_28f03d6e-955e-4f13-bed8-f574ff7530a2"
}