timdorr / tesla-api

🚘 A Ruby gem and unofficial documentation of Tesla's JSON API for the Model S, 3, X, and Y.

Home Page:https://tesla-api.timdorr.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Graphql queries

drnic opened this issue · comments

Inspired by the revelation that some of tesla's API is behind graphql in #539 (comment) I went hunting for some other graphql queries.

I found:

{
    "query": "\n    query getChargingVehicles {\n  me {\n    charging {\n      vehicles {\n        vin\n        carType\n        deliveryDate\n        imageUrl\n      }\n    }\n  }\n}\n    ",
    "operationName": "getChargingVehicles"
}
{
    "query": "\n    query getPendingBalances {\n  me {\n    charging {\n      balances {\n        list {\n          amount\n          countryCode\n          currencyCode\n          sessionFeeIds\n        }\n      }\n    }\n  }\n}\n    ",
    "operationName": "getPendingBalances"
}
{
    "query": "\n    query GetInstrumentBySource($paymentSource: PaymentGatewayPaymentSourceEnum!, $countryCode: String, $currencyCode: String) {\n  me {\n    payment {\n      getInstrumentBySource(\n        paymentSource: $paymentSource\n        countryCode: $countryCode\n        currencyCode: $currencyCode\n      ) {\n        expiryMonth\n        expiryYear\n        lastFourDigits\n        paymentChannels\n        paymentInstrumentType\n        accountType\n      }\n    }\n  }\n}\n    ",
    "variables": {
        "paymentSource": "SUPERCHARGE",
        "countryCode": "AU",
        "currencyCode": "AUD"
    },
    "operationName": "GetInstrumentBySource"
}

And the following that was mentioned in #539 (comment)

{
    "query": "\n    query getChargingHistoryV2($pageNumber: Int!, $sortBy: String, $sortOrder: SortByEnum) {\n  me {\n    charging {\n      historyV2(pageNumber: $pageNumber, sortBy: $sortBy, sortOrder: $sortOrder) {\n        data {\n          ...SparkHistoryItemFragment\n        }\n        totalResults\n        hasMoreData\n        pageNumber\n      }\n    }\n  }\n}\n    \n    fragment SparkHistoryItemFragment on SparkHistoryItem {\n  countryCode\n  programType\n  billingType\n  vin\n  isMsp\n  credit {\n    distance\n    distanceUnit\n  }\n  chargingPackage {\n    distance\n    distanceUnit\n    energyApplied\n  }\n  invoices {\n    fileName\n    contentId\n    invoiceType\n  }\n  chargeSessionId\n  siteLocationName\n  chargeStartDateTime\n  chargeStopDateTime\n  unlatchDateTime\n  fees {\n    ...SparkHistoryFeeFragment\n  }\n  vehicleMakeType\n  sessionId\n  surveyCompleted\n  surveyType\n  postId\n  cabinetId\n  din\n}\n    \n    fragment SparkHistoryFeeFragment on SparkHistoryFee {\n  sessionFeeId\n  feeType\n  payorUid\n  amountDue\n  currencyCode\n  pricingType\n  usageBase\n  usageTier1\n  usageTier2\n  usageTier3\n  usageTier4\n  rateBase\n  rateTier1\n  rateTier2\n  rateTier3\n  rateTier4\n  totalTier1\n  totalTier2\n  totalTier3\n  totalTier4\n  uom\n  isPaid\n  uid\n  totalBase\n  totalDue\n  netDue\n  status\n}\n    ",
    "variables": {
        "sortBy": "start_datetime",
        "sortOrder": "DESC",
        "pageNumber": 1
    },
    "operationName": "getChargingHistoryV2"
}

Currently we don't have a reference to any graphql calls in the https://tesla-api.timdorr.com/ site. Does anyone have a favourite way they've seen graphql API's documented; and have a suggestion how they'd appear on the api docs site?

This is a recently-added API, so building docs for it is a new thing. I will likely treat each operation name like an endpoint on the JSON side.

A good example to follow might be these Rivian API docs (which I plan to document as well when I get my R1T in the next month): https://rivian-api.kaedenb.org/app/vehicle-info

Just my 2 cents: but I don't think this repo should delve into documenting Tesla account related things.

Products and services, like vehicles, solar, battery packs, home/destination charging: cool, but imo publicly demonstrating access to things like billing address and other account level details: not so cool.

Of course this just pulls tighter on the need for Tesla to create an official API program.