LLM Prompts

Streamlining API Integration Automation with LLMs

Automate API integration tasks using LLMs to generate, test, and debug code.

The method

Apply these prompts in LLMs like ChatGPT to generate code snippets, debug integration issues, and create automated workflows. Use the ‘Code Interpreter’ or similar plugins for direct execution and testing.

The prompts

Prompt 1
I have a REST API endpoint at 'https://example.com/api/data' that requires authentication via an API key passed in the 'X-API-Key' header. I want to retrieve data and parse the JSON response. Using Python and the 'requests' library, generate a function that does the following:

1. Sends a GET request to the specified API endpoint.
2. Includes the API key in the 'X-API-Key' header.
3. Handles potential errors such as connection errors (requests.exceptions.RequestException) and HTTP status codes (e.g., 400, 401, 500).
4. Parses the JSON response and returns the data as a Python dictionary if the request is successful.
5. Returns 'None' if the request fails or if the response is not valid JSON.

Include error handling with appropriate log messages and clear explanations. Also, demonstrate how to call this function and print the returned data or error message.
Prompt 2
I'm using a SOAP API that requires me to send XML requests and process XML responses. The WSDL file is located at 'https://example.com/api/service.wsdl'. My goal is to create a function that can send a specific request and parse the relevant data from the response. Use Python and the 'zeep' library. Write a function that:

1. Loads the WSDL file from the provided URL.
2. Creates a SOAP client.
3. Constructs an XML request using the 'GetUserDetails' operation, with the parameter 'userID' set to '12345'.
4. Sends the SOAP request.
5. Parses the XML response and extracts the 'userName' and 'emailAddress' values.
6. Returns a dictionary containing 'userName' and 'emailAddress'.
7. Handles exceptions like network errors and SOAP faults.

Include relevant error handling and explain how to call this function to display the extracted user details or handle any potential errors.
Prompt 3
I want to create an automated workflow using Make (formerly Integromat) to post new blog articles from a WordPress site to a Discord channel. The trigger should be when a new post is published on the WordPress site, and the action should be to send a message to a specific Discord channel. Use the following guidelines:

1. **WordPress Trigger:** Use the 'New Post' trigger in the WordPress module.
2. **Discord Action:** Use the 'Create a Message' action in the Discord module.
3. **Connection:** Assume that the WordPress and Discord connections have already been established in Make.
4. **Message Content:** The Discord message should include the title of the blog post, the author's name, and a link to the post. Format the message in Markdown for better readability.
5. **Error Handling:** Briefly describe how to implement error handling to catch scenarios where the connection to WordPress or Discord fails.

Detail each step, from setting up the trigger to configuring the action. Provide the specific data mappings required to ensure the correct information is sent to Discord. Explain how to test the scenario to confirm it works as expected. Briefly describe how to set up error handling to deal with potential connectivity issues.