Hi @Lili13,
Please check the syntax.
import frappe
def get_customer_details(customer_name):
base_url = "example.com"
endpoint = "/api/resource/Customer"
fields = ["name", "customer_name"]
query_params = f"?fields={fields}"
url = f"{base_url}{endpoint}{query_params}"
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN', # Replace with your actual access token
'Content-Type': 'application/json',
}
response = frappe.get_request(url, headers=headers)
# Process the response as needed
if response.status_code == 200:
customer_data = response.json() # Convert JSON response to Python dictionary
return customer_data
else:
frappe.throw(f"Failed to fetch customer details: {response.status_code} - {response.text}")
# Call the function with the desired customer name
customer_name = "desired_customer_name"
customer_details = get_customer_details(customer_name)
Reference:
Thank You!