Update a user via admin api got 501 not implemented error

{
  `user_id`: `1`,
  `location`: `NY,US`
}
Error executing tool update_user: HTTP error accessing Ghost API: Server error '501 Not Implemented' for url 'https://ghost_adomin/ghost/api/admin/users/1'

However, list users and read users works well

I think you’ll need to post your exact request (endpoint and body and headers) if you want help.

import asyncio
import json
import time
import jwt
import httpx

# Configuration
API_URL = ""
STAFF_API_KEY = ""

async def get_auth_headers(api_key: str) -> dict:
    """Generate authentication headers for Ghost Admin API."""
    [id, secret] = api_key.split(':')
    
    iat = int(time.time())
    header = {
        'alg': 'HS256',
        'typ': 'JWT',
        'kid': id
    }
    payload = {
        'iat': iat,
        'exp': iat + 5 * 60,
        'aud': '/admin/'
    }
    
    token = jwt.encode(payload, bytes.fromhex(secret), algorithm='HS256', headers=header)
    return {'Authorization': f'Ghost {token}'}

async def make_request(endpoint: str, headers: dict, method: str = "GET", json_data: dict = None) -> dict:
    """Make an HTTP request to the Ghost Admin API."""
    url = f"{API_URL}/ghost/api/admin/{endpoint}"
    
    print(f"\nDebug Info:")
    print(f"URL: {url}")
    print(f"Method: {method}")
    print(f"Headers: {headers}")
    if json_data:
        print(f"Request Data: {json.dumps(json_data, indent=2)}")
    
    async with httpx.AsyncClient() as client:
        if method == "GET":
            response = await client.get(url, headers=headers)
        elif method == "PUT":
            response = await client.put(url, headers=headers, json=json_data)
        elif method == "PATCH":
            response = await client.patch(url, headers=headers, json=json_data)
        else:
            raise ValueError(f"Unsupported HTTP method: {method}")
        
        print(f"Response Status: {response.status_code}")
        print(f"Response Headers: {dict(response.headers)}")
        print(f"Response Body: {response.text}")
        
        if response.status_code >= 400:
            raise Exception(f"API request failed: {response.text}")
            
        return response.json()

async def read_user(user_id: str) -> str:
    """Get details of a specific user."""
    try:
        # Generate authentication headers
        headers = await get_auth_headers(STAFF_API_KEY)
        
        # Make the request to get user details
        response = await make_request(
            f"users/{user_id}/?include=roles",
            headers
        )
        
        # Process and return the result
        user = response.get("users", [{}])[0]
        roles = [role.get('name') for role in user.get('roles', [])]
        
        return f"""
User details:
Name: {user.get('name', 'Unknown')}
Email: {user.get('email', 'Unknown')}
Slug: {user.get('slug', 'Unknown')}
Status: {user.get('status', 'Unknown')}
Roles: {', '.join(roles)}
Location: {user.get('location', 'Not specified')}
Website: {user.get('website', 'None')}
Bio: {user.get('bio', 'No bio')}
Created: {user.get('created_at', 'Unknown')}
Last Seen: {user.get('last_seen', 'Never')}
"""
    except Exception as e:
        return f"Error reading user: {str(e)}"

async def update_user(user_id: str, location: str) -> str:
    """Update a user's location in Ghost."""
    try:
        # Generate authentication headers
        headers = await get_auth_headers(STAFF_API_KEY)
        
        # Prepare update data
        update_data = {
            "users": [{
                "location": location
            }]
        }
        
        # Make the update request
        response = await make_request(
            f"users/{user_id}/",
            headers,
            method="PATCH",
            json_data=update_data
        )
        
        # Process and return the result
        user = response.get("users", [{}])[0]
        return f"""
User updated successfully:
Name: {user.get('name', 'Unknown')}
Email: {user.get('email', 'Unknown')}
Location: {user.get('location', 'Not specified')}
Updated: {user.get('updated_at', 'Unknown')}
"""
    except Exception as e:
        return f"Error updating user: {str(e)}"

async def test_user_operations():
    # First read the current user details
    print("Reading user details before update...")
    result = await read_user("1")
    print(result)
    
    print("\nUpdating user location...")
    # Then update the user's location
    result = await update_user("1", "NY,US")
    print(result)
    
    print("\nReading user details after update...")
    # Read again to verify the update
    result = await read_user("1")
    print(result)

if __name__ == "__main__":
    asyncio.run(test_user_operations())

This is the test code