Discussions
How to get the generated text of my workflow via a call to my API?
The calling to my API is fine, but i get for an answear something like this
"Enter the article URL: https://www.cryptopolitan.com/south-korea-crypto-regulations-sec-chair/
Request to Copy.ai API successful!
Generated Text:"
The generated text is not here because it's being generated after this answear.
Here is my code :
import requests
Copy.ai API information
api_key "xxx"
api_endpoint = "xxx"
Prompt the user to enter a link
article_url = input("Enter the article URL: ")
Prepare payload and headers
payload = {
"startVariables": {"article_url": article_url},
"metadata": {"api": True}
}
headers = {
"Content-Type": "application/json",
"x-copy-ai-api-key": api_key
}
Make a request to the Copy.ai API
response = requests.post(api_endpoint, json=payload, headers=headers)
Check the response for the API call
if response.status_code == 201 or response.status_code == 200:
print("Request to Copy.ai API successful!")
# Extract and print the generated text
generated_text = response.json().get("data", {}).get("output_text", "")
print("Generated Text:")
print(generated_text)
else:
print(f"Error: {response.status_code} - {response.text}")