r-spacex / SpaceX-API

:rocket: Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Apache License 2.0
10.52k stars 938 forks source link

Getting booster (cores) info in /launches query #745

Closed yosefeliezrie closed 3 years ago

yosefeliezrie commented 3 years ago

Hello,

I am currently using the /launches/query endpoint to get data from the API. Ideally, i would like to get the booster number and info (see this page under "Booster Information" for an example https://spacelaunchnow.me/launch/falcon-9-block-5-spx-uscv-2-nasa-crew-flight-2/), In my query i am using populate to add "cores" but it only returns limited data. Is there a way to return all the data on the cores for that launch without another API call to the /cores/:id endpoint?

Launch Query

{
    "query": {
        "_id": "5fe3af58b3467846b324215f"
    },
    "options": {
        "populate": [
            "payloads",
            "rocket",
            "landpad",
            "launchpad",
            "ships",
            "crew",
            "dragons"
        ],
        "limit": 1
    }
}

Results

{
    "data": {
        "docs": [
            {
                "fairings": {
                    "reused": null,
                    "recovery_attempt": null,
                    "recovered": null,
                    "ships": []
                },
                "links": {
                    "patch": {
                        "small": "https://imgur.com/NPFaJDF.png",
                        "large": "https://imgur.com/65vp2PE.png"
                    },
                    "reddit": {
                        "campaign": null,
                        "launch": null,
                        "media": null,
                        "recovery": null
                    },
                    "flickr": {
                        "small": [],
                        "original": []
                    },
                    "presskit": null,
                    "webcast": null,
                    "youtube_id": null,
                    "article": null,
                    "wikipedia": null
                },
                "static_fire_date_utc": null,
                "static_fire_date_unix": null,
                "tbd": false,
                "net": false,
                "window": 0,
                "rocket": {
                    "height": {
                        "meters": 70,
                        "feet": 229.6
                    },
                    "diameter": {
                        "meters": 3.7,
                        "feet": 12
                    },
                    "mass": {
                        "kg": 549054,
                        "lb": 1207920
                    },
                    "first_stage": {
                        "thrust_sea_level": {
                            "kN": 7607,
                            "lbf": 1710000
                        },
                        "thrust_vacuum": {
                            "kN": 8227,
                            "lbf": 1849500
                        },
                        "reusable": true,
                        "engines": 9,
                        "fuel_amount_tons": 385,
                        "burn_time_sec": 162
                    },
                    "second_stage": {
                        "thrust": {
                            "kN": 934,
                            "lbf": 210000
                        },
                        "payloads": {
                            "composite_fairing": {
                                "height": {
                                    "meters": 13.1,
                                    "feet": 43
                                },
                                "diameter": {
                                    "meters": 5.2,
                                    "feet": 17.1
                                }
                            },
                            "option_1": "dragon"
                        },
                        "reusable": false,
                        "engines": 1,
                        "fuel_amount_tons": 90,
                        "burn_time_sec": 397
                    },
                    "engines": {
                        "isp": {
                            "sea_level": 288,
                            "vacuum": 312
                        },
                        "thrust_sea_level": {
                            "kN": 845,
                            "lbf": 190000
                        },
                        "thrust_vacuum": {
                            "kN": 914,
                            "lbf": 205500
                        },
                        "number": 9,
                        "type": "merlin",
                        "version": "1D+",
                        "layout": "octaweb",
                        "engine_loss_max": 2,
                        "propellant_1": "liquid oxygen",
                        "propellant_2": "RP-1 kerosene",
                        "thrust_to_weight": 180.1
                    },
                    "landing_legs": {
                        "number": 4,
                        "material": "carbon fiber"
                    },
                    "payload_weights": [
                        {
                            "id": "leo",
                            "name": "Low Earth Orbit",
                            "kg": 22800,
                            "lb": 50265
                        },
                        {
                            "id": "gto",
                            "name": "Geosynchronous Transfer Orbit",
                            "kg": 8300,
                            "lb": 18300
                        },
                        {
                            "id": "mars",
                            "name": "Mars Orbit",
                            "kg": 4020,
                            "lb": 8860
                        }
                    ],
                    "flickr_images": [
                        "https://farm1.staticflickr.com/929/28787338307_3453a11a77_b.jpg",
                        "https://farm4.staticflickr.com/3955/32915197674_eee74d81bb_b.jpg",
                        "https://farm1.staticflickr.com/293/32312415025_6841e30bf1_b.jpg",
                        "https://farm1.staticflickr.com/623/23660653516_5b6cb301d1_b.jpg",
                        "https://farm6.staticflickr.com/5518/31579784413_d853331601_b.jpg",
                        "https://farm1.staticflickr.com/745/32394687645_a9c54a34ef_b.jpg"
                    ],
                    "name": "Falcon 9",
                    "type": "rocket",
                    "active": true,
                    "stages": 2,
                    "boosters": 0,
                    "cost_per_launch": 50000000,
                    "success_rate_pct": 97,
                    "first_flight": "2010-06-04",
                    "country": "United States",
                    "company": "SpaceX",
                    "wikipedia": "https://en.wikipedia.org/wiki/Falcon_9",
                    "description": "Falcon 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable and safe transport of satellites and the Dragon spacecraft into orbit.",
                    "id": "5e9d0d95eda69973a809d1ec"
                },
                "success": null,
                "details": "SpaceX launches the second operational mission of its Crew Dragon vehicle as part of NASA's Commercial Crew Program, carrying NASA astronauts Shane Kimbrough, Megan McArthur, Thomas Pesquet, and Akihiko Hoshide to the International Space Station. The Falcon 9 and Crew Dragon lift off from LC-39A, Kennedy Space Center. Both the booster and the capsule have flown previously, each a first for a commercial crew flight. The booster for this mission is expected to land on an ASDS. The mission will be complete with the safe return of the astronauts to Earth.",
                "crew": [
                    {
                        "name": "Shane Kimbrough",
                        "agency": "NASA",
                        "image": "https://imgur.com/nwxqtcT.png",
                        "wikipedia": "https://en.wikipedia.org/wiki/Shane_Kimbrough",
                        "launches": [],
                        "status": "active",
                        "id": "5fe3ba5fb3467846b3242188"
                    },
                    {
                        "name": "K. Megan McArthur",
                        "agency": "NASA",
                        "image": "https://imgur.com/0VNXcdM.png",
                        "wikipedia": "https://en.wikipedia.org/wiki/K._Megan_McArthur",
                        "launches": [],
                        "status": "active",
                        "id": "5fe3bb01b3467846b3242189"
                    },
                    {
                        "name": "Thomas Pesquet",
                        "agency": "ESA",
                        "image": "https://imgur.com/5iColcZ.png",
                        "wikipedia": "https://en.wikipedia.org/wiki/Thomas_Pesquet",
                        "launches": [],
                        "status": "active",
                        "id": "5fe3bc3db3467846b324218b"
                    },
                    {
                        "name": "Akihiko Hoshide",
                        "agency": "JAXA",
                        "image": "https://imgur.com/GefuPYs.png",
                        "wikipedia": "https://en.wikipedia.org/wiki/Akihiko_Hoshide",
                        "launches": [],
                        "status": "active",
                        "id": "5fe3bc8ab3467846b324218c"
                    }
                ],
                "ships": [],
                "capsules": [
                    "5e9e2c5df359188aba3b2676"
                ],
                "payloads": [
                    {
                        "dragon": {
                            "capsule": "5e9e2c5df359188aba3b2676",
                            "mass_returned_kg": null,
                            "mass_returned_lbs": null,
                            "flight_time_sec": null,
                            "manifest": null,
                            "water_landing": null,
                            "land_landing": null
                        },
                        "name": "Crew-2",
                        "type": "Crew Dragon",
                        "reused": false,
                        "launch": "5fe3af58b3467846b324215f",
                        "customers": [
                            "NASA (CCtCap)"
                        ],
                        "norad_ids": [],
                        "nationalities": [
                            "United States"
                        ],
                        "manufacturers": [
                            "SpaceX"
                        ],
                        "mass_kg": null,
                        "mass_lbs": null,
                        "orbit": "ISS",
                        "reference_system": "geocentric",
                        "regime": "low-earth",
                        "longitude": null,
                        "semi_major_axis_km": null,
                        "eccentricity": null,
                        "periapsis_km": null,
                        "apoapsis_km": null,
                        "inclination_deg": null,
                        "period_min": null,
                        "lifespan_years": null,
                        "epoch": null,
                        "mean_motion": null,
                        "raan": null,
                        "arg_of_pericenter": null,
                        "mean_anomaly": null,
                        "id": "5fe3b3adb3467846b3242173"
                    }
                ],
                "launchpad": {
                    "name": "KSC LC 39A",
                    "full_name": "Kennedy Space Center Historic Launch Complex 39A",
                    "locality": "Cape Canaveral",
                    "region": "Florida",
                    "timezone": "America/New_York",
                    "latitude": 28.6080585,
                    "longitude": -80.6039558,
                    "launch_attempts": 32,
                    "launch_successes": 32,
                    "rockets": [
                        "5e9d0d95eda69973a809d1ec",
                        "5e9d0d95eda69974db09d1ed"
                    ],
                    "launches": [
                        "5eb87cfeffd86e000604b34d",
                        "5eb87cfeffd86e000604b34e",
                        "5eb87d00ffd86e000604b34f",
                        "5eb87d01ffd86e000604b350",
                        "5eb87d01ffd86e000604b351",
                        "5eb87d03ffd86e000604b352",
                        "5eb87d04ffd86e000604b353",
                        "5eb87d06ffd86e000604b355",
                        "5eb87d07ffd86e000604b356",
                        "5eb87d09ffd86e000604b358",
                        "5eb87d0cffd86e000604b35a",
                        "5eb87d0dffd86e000604b35b",
                        "5eb87d13ffd86e000604b360",
                        "5eb87d19ffd86e000604b366",
                        "5eb87d24ffd86e000604b36f",
                        "5eb87d2bffd86e000604b375",
                        "5eb87d2dffd86e000604b376",
                        "5eb87d35ffd86e000604b37a",
                        "5eb87d3dffd86e000604b381",
                        "5eb87d43ffd86e000604b385",
                        "5eb87d44ffd86e000604b386",
                        "5eb87d46ffd86e000604b388",
                        "5ed9819a1f30554030d45c29",
                        "5ef6a1e90059c33cee4a828a",
                        "5ef6a2090059c33cee4a828b",
                        "5ef6a2bf0059c33cee4a828c",
                        "5eb87d4dffd86e000604b38e",
                        "5eb87d4effd86e000604b391",
                        "5f8399fb818d8b59f5740d43",
                        "5fbfecce54ceb10a5664c80a",
                        "5fbfecfe54ceb10a5664c80b",
                        "600f9a8d8f798e2a4d5f979e"
                    ],
                    "details": "NASA's historic pad that launched most of the Saturn V and Space Shuttle missions, including Apollo 11. SpaceX initially leased solely for Falcon Heavy and Crew Dragon launches, but the company has also used it for others as well following the damage to SLC-40 in the AMOS-6 explosion. After completing the necessary modifications, the first launch SpaceX performed on the pad was CRS-10 in February 2017. After SLC-40 was back online, 39A was upgraded to support Falcon Heavy and complete the removal of the shuttle-era Rotating Service Structure. More recently, a crew access arm and other safety equipment has been installed in order to launch commercial crew missions. 39A also occasionally launches other Falcon 9 missions between Falcon Heavy and Crew Dragon launches, depending on pad scheduling. The pad may also potentially be upgraded in the future for use with the BFR.",
                    "status": "active",
                    "id": "5e9e4502f509094188566f88"
                },
                "auto_update": true,
                "launch_library_id": "4d8c6991-4fa4-4ea9-925a-33b083bbf146",
                "failures": [],
                "flight_number": 123,
                "name": "Crew-2",
                "date_utc": "2021-04-22T10:11:00.000Z",
                "date_unix": 1619086260,
                "date_local": "2021-04-22T06:11:00-04:00",
                "date_precision": "hour",
                "upcoming": true,
                "cores": [
                    {
                        "core": "5f57c53d0622a6330279009f",
                        "flight": 2,
                        "gridfins": true,
                        "legs": true,
                        "reused": true,
                        "landing_attempt": true,
                        "landing_success": null,
                        "landing_type": "ASDS",
                        "landpad": null
                    }
                ],
                "id": "5fe3af58b3467846b324215f"
            }
        ],
        "totalDocs": 1,
        "offset": 0,
        "limit": 1,
        "totalPages": 1,
        "page": 1,
        "pagingCounter": 1,
        "hasPrevPage": false,
        "hasNextPage": false,
        "prevPage": null,
        "nextPage": null
    },
    "status": 200,
    "statusText": "",
    "headers": {
        "cache-control": "max-age=20",
        "content-type": "application/json; charset=utf-8",
        "spacex-api-cache": "HIT",
        "spacex-api-response-time": "0ms"
    },
    "config": {
        "url": "https://api.spacexdata.com/v4/launches/query",
        "method": "post",
        "data": "{\"query\":{\"_id\":\"5fe3af58b3467846b324215f\"},\"options\":{\"populate\":[\"payloads\",\"rocket\",\"landpad\",\"launchpad\",\"ships\",\"crew\",\"dragons\"],\"limit\":1}}",
        "headers": {
            "Accept": "application/json, text/plain, */*",
            "Content-Type": "application/json;charset=utf-8"
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1,
        "maxBodyLength": -1
    },
    "request": {}
}
yosefeliezrie commented 3 years ago

in addition, Is there a way to get the booster core serial and status without another API call to the cores/:id endpoint?

jakewmeyer commented 3 years ago

Yeah! Pretty close already, just need the cores.core bit

{
    "query": {
        "_id": "5fe3af58b3467846b324215f"
    },
    "options": {
        "populate": [
            "payloads",
            "rocket",
            "landpad",
            "launchpad",
            "ships",
            "crew",
            "dragons",
            "cores.core"
        ],
        "limit": 1
    }
}