R
RunPod•6mo ago
untech

How to remove endpoint via Python API?

Hello, in Python API, you can create new endpoints. Is there a way to remove endpoints? Also, I can't find a way to get a list of templates programmatically. Thanks!
Solution:
or, if you just want a python function: ```python import requests import runpod ...
Jump to solution
8 Replies
nerdylive
nerdylive•6mo ago
There is onnthe graphql API reference
untech
untechOP•6mo ago
Ok, sure, so I can execute this query from Python? Thanks! Even in graphql, however, I can't find a way to list all templates. Is there any?
yhlong00000
yhlong00000•6mo ago
https://graphql-spec.runpod.io/#query-myself Search PodTemplate, there you can I believe.
nerdylive
nerdylive•6mo ago
Try to use postman, see the code generated part in right side (postman). ( google how to do this if you want ), theres a graphql input that is compatible and good for testing already in postman
jjdademon
jjdademon•6mo ago
To save the next person some time with this. 1. Write a POST request in postman 2. Set URL to: https://api.runpod.io/graphql?api_key=xxxxxxx ^Replace xxxx with your API key 3. Add headers: Key: Accept, Value: application/json 4. In body, select GraphQL and send the following text
query {
myself {
podTemplates {
id
}
}
}
query {
myself {
podTemplates {
id
}
}
}
5. hit send, you should get the list of podTemplates.
Solution
jjdademon
jjdademon•6mo ago
or, if you just want a python function:
import requests
import runpod
import os

def get_templates():

# The API endpoint
url = "https://api.runpod.io/graphql"

# Your API key
api_key = os.getenv("RUNPOD_API_KEY") # You can replace this with your api key

# The GraphQL query
query = """
query {
myself {
podTemplates {
id
}
}
}
"""

# Headers
headers = {
"Content-Type": "application/json",
}

# The request payload
payload = {
"query": query
}

# Send the POST request
response = requests.post(url, json=payload, headers=headers, params={"api_key": api_key})

if response.status_code == 200:
data = response.json()
pod_templates = data.get('data', {}).get('myself', {}).get('podTemplates', [])
template_ids = [template['id'] for template in pod_templates]
else:
print(f"Error: {response.status_code}")
print(response.text)

return template_ids

templates = get_templates()

print(templates)
import requests
import runpod
import os

def get_templates():

# The API endpoint
url = "https://api.runpod.io/graphql"

# Your API key
api_key = os.getenv("RUNPOD_API_KEY") # You can replace this with your api key

# The GraphQL query
query = """
query {
myself {
podTemplates {
id
}
}
}
"""

# Headers
headers = {
"Content-Type": "application/json",
}

# The request payload
payload = {
"query": query
}

# Send the POST request
response = requests.post(url, json=payload, headers=headers, params={"api_key": api_key})

if response.status_code == 200:
data = response.json()
pod_templates = data.get('data', {}).get('myself', {}).get('podTemplates', [])
template_ids = [template['id'] for template in pod_templates]
else:
print(f"Error: {response.status_code}")
print(response.text)

return template_ids

templates = get_templates()

print(templates)
nerdylive
nerdylive•6mo ago
Thank you for sharing
yhlong00000
yhlong00000•6mo ago
😋 we should have this in RunPod Docs~
Want results from more Discord servers?
Add your server