[Python] How to query all possible field value when not knowing all possible arguments on...

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to query the Slab API, they use GraphQL but I do not know of it.

    The API defines a Post object that takes an ID as an input and outputs its content and other metadata, among them the title and content. I'd like to query the title and content of every available Post object but I don't know every possible value of the ID argument.

    I can easily query for a specific post object given its ID using that piece of code

    import requests

    # Define the GraphQL endpoint
    url = 'https://api.slab.com/v1/graphql'

    # GraphQL query
    query = """
    {
    post(id: "987fbw7k") {
    title
    content
    }
    }
    """

    # Set the headers
    headers = {
    'content-type': 'application/json',
    'Authorization': 'API_KEY_HERE'
    }

    # Payload
    payload = {
    'query': query
    }

    # Make the request
    response = requests.post(url, json=payload, headers=headers)
    print(response.json())


    How do I get a list of the titles & content of all possible Post objects, without knowing every possible IDs ?

    Thanks a lot

    Continue reading...

Compartilhe esta Página