#!/usr/bin/env python3 """ Test Adobe Photoshop Text Editing API This script makes a direct request to the Adobe text editing API with various payload formats to analyze the responses and understand exactly what's required. """ import json import requests from adobe_token import AdobeTokenManager import config # Initialize token manager token_manager = AdobeTokenManager(config.ADOBE_CLIENT_ID, config.ADOBE_CLIENT_SECRET) def test_text_api(): """Test the Adobe Photoshop Text API with detailed analysis""" # Get a token try: access_token, _ = token_manager.get_token(config.DEFAULT_SCOPES) except Exception as e: print(f"Error getting token: {str(e)}") return # Endpoints to test endpoints = [ "https://image.adobe.io/pie/psdService/text", ] # Headers for API requests headers = { "x-api-key": config.ADOBE_CLIENT_ID, "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } # Test various payload formats payload_formats = [ # Format 1 - Based on ALL error message feedback - FULLY CORRECTED { "inputs": [ { "href": "/temp/test-document-id.psd", "storage": "adobe" } ], "options": { "layers": [ { "id": 1, # Must be integer "text": { # Must be object "content": "SPECIALLY DESIGNED FOREXTRA SENSITIVE SKIN" } } ] }, "outputs": [ { "href": "/temp/output-test-document-id.psd", "storage": "adobe", "type": "image/vnd.adobe.photoshop" } ] }, # Format 2 - Using name instead of id { "inputs": [ { "href": "/cloud-content/test-document-id.psd", "storage": "adobe" } ], "options": { "layers": [ { "name": "DESIGNED FOR SENSITIVE SKIN", # Using name "text": { # As object "content": "SPECIALLY DESIGNED FOREXTRA SENSITIVE SKIN" } } ] }, "outputs": [ { "href": "/cloud-content/output-test-document-id.psd", "storage": "adobe", "type": "image/vnd.adobe.photoshop" } ] }, # Format 3 - Minimal format with just the requirements { "inputs": [ { "href": "/temp/test-document-id.psd", "storage": "adobe" } ], "options": { "layers": [ { "id": 1, "text": { "content": "SPECIALLY DESIGNED FOREXTRA SENSITIVE SKIN" } } ] }, "outputs": [ { "href": "/temp/output-test-document-id.psd", "storage": "adobe", "type": "image/vnd.adobe.photoshop" } ] } ] # Test each endpoint for endpoint in endpoints: print(f"\nTesting endpoint: {endpoint}") # First try a GET request to check access try: get_response = requests.get(endpoint, headers=headers, timeout=10) print(f"GET response: {get_response.status_code}") if get_response.text: print(f"Response content: {get_response.text[:500]}") except Exception as e: print(f"Error with GET request: {str(e)}") # Test each payload format for i, payload in enumerate(payload_formats): try: print(f"\nTesting Format {i+1}:") print(f"Payload: {json.dumps(payload, indent=2)}") response = requests.post(endpoint, headers=headers, json=payload, timeout=20) print(f"Response status: {response.status_code}") if response.text: try: # Try to parse as JSON resp_json = response.json() print(f"Response (JSON): {json.dumps(resp_json, indent=2)}") except: # Otherwise print as text print(f"Response: {response.text[:1000]}") except Exception as e: print(f"Error with Format {i+1}: {str(e)}") if __name__ == "__main__": test_text_api()