Skip to main content
PUT
/
api
/
clients
/
:id
Update Client
curl --request PUT \
  --url https://api.example.com/api/clients/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "domain": "<string>",
  "contactName": "<string>",
  "contactEmail": "<string>"
}
'
{
  "id": "<string>",
  "name": "<string>",
  "domain": "<string>",
  "contactName": "<string>",
  "contactEmail": "<string>",
  "userId": "<string>",
  "googleSearchConsoleConnected": true,
  "googleAnalyticsConnected": true,
  "createdAt": "<string>",
  "updatedAt": "<string>",
  "reports": [
    {}
  ],
  "error": "<string>",
  "details": [
    {}
  ]
}

Authentication

Requires authenticated user session. User must own the client being updated.

Path Parameters

id
string
required
The unique identifier of the client to update

Request Body

All fields are optional. Only include fields you want to update.
name
string
Client name (minimum 2 characters if provided)
domain
string
Client website domain (must be valid URL if provided)
contactName
string
Primary contact person’s name
contactEmail
string
Primary contact email (must be valid email format if provided)

Response

Returns the updated client object with the most recent report included.
id
string
Client identifier
name
string
Updated client name
domain
string
Updated client domain
contactName
string
Updated contact name
contactEmail
string
Updated contact email
userId
string
ID of the user who owns this client
googleSearchConsoleConnected
boolean
Google Search Console connection status
googleAnalyticsConnected
boolean
Google Analytics connection status
createdAt
string
ISO 8601 timestamp when client was created
updatedAt
string
ISO 8601 timestamp reflecting the update
reports
array
Array containing the most recent report (if any)

Validation Rules

  • name: Minimum 2 characters (if provided)
  • domain: Must be a valid URL format (if provided)
  • contactEmail: Must be valid email format (if provided)

Error Responses

error
string
Error message describing what went wrong
details
array
Validation error details (400 errors)

Example Request

cURL
curl -X PUT https://your-domain.com/api/clients/clx1a2b3c4d5e6f7g8h9i0j1k \
  -H "Content-Type: application/json" \
  -H "Cookie: next-auth.session-token=..." \
  -d '{
    "name": "Acme Corp (Updated)",
    "contactEmail": "[email protected]"
  }'
JavaScript
const response = await fetch('/api/clients/clx1a2b3c4d5e6f7g8h9i0j1k', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Acme Corp (Updated)',
    contactEmail: '[email protected]'
  })
});

const updatedClient = await response.json();

Example Response

200 Success
{
  "id": "clx1a2b3c4d5e6f7g8h9i0j1k",
  "name": "Acme Corp (Updated)",
  "domain": "https://acme.com",
  "contactName": "John Doe",
  "contactEmail": "[email protected]",
  "userId": "clx0a1b2c3d4e5f6g7h8i9j0k",
  "googleSearchConsoleConnected": true,
  "googleAnalyticsConnected": true,
  "searchConsolePropertyUrl": "https://acme.com",
  "googleAnalyticsPropertyId": "123456789",
  "gscSiteUrl": "https://acme.com",
  "gscSiteName": "Acme Corporation",
  "ga4PropertyId": "123456789",
  "ga4PropertyName": "Acme GA4 Property",
  "googleConnectedAt": "2024-03-15T11:00:00.000Z",
  "lastReportGenerated": "2024-03-20T14:30:00.000Z",
  "totalReportsGenerated": 5,
  "createdAt": "2024-03-15T10:30:00.000Z",
  "updatedAt": "2024-03-21T16:45:00.000Z",
  "reports": [
    {
      "id": "clx9z8y7x6w5v4u3t2s1r0q",
      "title": "March 2024 Report",
      "status": "COMPLETED",
      "pdfUrl": "https://blob.vercel-storage.com/...",
      "createdAt": "2024-03-20T14:30:00.000Z"
    }
  ]
}
400 Validation Error
{
  "error": "Validation error",
  "details": [
    {
      "code": "invalid_string",
      "validation": "email",
      "message": "Must be a valid email",
      "path": ["contactEmail"]
    }
  ]
}
404 Not Found
{
  "error": "Client not found or unauthorized"
}
401 Unauthorized
{
  "error": "Unauthorized"
}

Notes

  • Only the client owner can update client information
  • Attempting to update a non-existent client or another user’s client returns 404
  • Partial updates are supported - only send fields you want to change
  • The updatedAt timestamp is automatically updated on each change
  • Google connection fields (tokens, property IDs) cannot be updated via this endpoint

Build docs developers (and LLMs) love