Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Iterative Macro for Repeated HTTP Request Automation in Alteryx

JonasZeng
5 - Atom
Please help to create an Alteryx iterative macro for repeatedly making HTTP requests.
The steps are as follows:
  1. The input contains a URL and a body.
  2. Then, use the Download tool to make the HTTP request. If the result obtained is not empty, output this result, and replace the body in the previous input with the value of the body from the last row of the result. Then, perform the request again using this updated body.
  3. Repeat the loop until the result is empty, then exit the loop

Please feel free to ask me anything if you need. Thanks.

1 REPLY 1
Warcry
9 - Comet

Use the python tool for ease, since you didn't say much about the API you'll be calling, here is a vague example. If you have would have said like Azure Storage or like Jira then I can provide a script for that. In python, you'll be able to create all the loops you so desire.

 

--------------------------------------------

import requests
import pandas as pd
 
# Initial Input: URL and body
url = "https://example.com/api"  # Replace with your API endpoint
initial_body = {"key": "value"}  # Replace with your initial body (in JSON or text format)
 
# Create a list to store results
results = []
 
# Loop to make HTTP requests
current_body = initial_body
while True:
    # Make the HTTP request
    response = requests.post(url, json=current_body)
    
    # Check if the request was successful
    if response.status_code != 200:
        print(f"Request failed with status code: {response.status_code}")
        break
    
    # Parse the response data (assuming JSON format)
    result = response.json()
    if not result:  # Exit loop if the result is empty
        break
    
    # Store the result
    results.append(result)
    
    # Update the current_body with the last row's body value from the result
    # Assuming result is a list of dictionaries and "body" is the field to update
    current_body = result[-1].get("body", {})
    
# Convert results to a pandas DataFrame (if needed)
results_df = pd.DataFrame(results)
 
# Output the results (to Alteryx or save to file)
print("Results:", results_df)

 

Labels
Top Solution Authors