Import a connection by submitting credentials directly (programmatic)

Porte B (programmatic/headless): the backend already holds the credential and submits it directly to create the connection — the server-to-server analogue of the hosted Connect portal. Use for api_key / basic / custom auths, and for an oauth2 auth declaring connect.login (AFPS §7.7): the grant its login renders from the submitted credentials (for example a refresh token) is sent to the token endpoint before the connection is stored, and a grant the server refuses is a 400 login_rejected, an OAuth client it refuses a 502 oauth_client_rejected. The answer must carry token_type Bearer; a response without scope is granted the scope the grant requested, if any; identity comes from the token response and userinfo_endpoint, never from an id_token, which is not validated. For other OAuth2 auths use the headless OAuth start (initiateIntegrationOAuth); for interactive/human flows where the secret should never transit the caller, use the hosted Connect portal (initiateIntegrationConnect).

A credential the platform mints (the private_key of @appstrate/ssh) is refused with a 400 naming the field; such an auth connects through the Connect portal (initiateIntegrationConnect).

POST/api/integrations/{packageId}/auths/{authKey}/connect/fields

Authorization

better-auth.session_token<token>

Cookie session from Better Auth. Requires X-Org-Id header for org-scoped routes.

In: cookie

Path Parameters

packageId*string

Integration package id (e.g. @official/gmail).

Match^@[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9-]*$
authKey*string

Auth key as declared in the manifest's auths map.

Match^[a-z][a-z0-9_]*$

Header Parameters

X-Org-Id?string

Organization ID. Required for cookie auth. Not needed for API key auth (org resolved from key).

Formatuuid
X-Space-Id?string

Space ID. Required for space-scoped routes (agents, runs, schedules, and space-scoped module routes). Not needed for API key auth (space resolved from key).

Request Body

application/json

curl -X POST "https://your-instance/api/integrations/string/auths/string/connect/fields" \  -H "Content-Type: application/json" \  -d '{    "credentials": {}  }'
{
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "integration_package_id": "string",
  "auth_key": "string",
  "account_id": "string",
  "identity_claims": {},
  "scopes_granted": [
    "string"
  ],
  "needs_reconnection": true,
  "expiresAt": "2019-08-24T14:15:22Z",
  "owner_type": "user",
  "owner_id": "string",
  "owner_name": "string",
  "locked_by": "admin_pin",
  "label": "string",
  "scope": "org",
  "spaceId": "string",
  "shared_here": true,
  "shared_space_ids": [
    "string"
  ],
  "share_all_spaces": true,
  "origin_space_id": "string",
  "allowed_actions": [
    "rename"
  ],
  "shareable_spaces": [
    {
      "id": "string",
      "name": "string"
    }
  ],
  "client_ref": "string",
  "variables": {
    "property1": "string",
    "property2": "string"
  },
  "createdAt": "2019-08-24T14:15:22Z",
  "updatedAt": "2019-08-24T14:15:22Z"
}

{
  "type": "https://docs.appstrate.dev/errors/validation-failed",
  "title": "Validation Failed",
  "status": 400,
  "detail": "name: Invalid input: expected string, received undefined (+2 more)",
  "code": "validation_failed",
  "request_id": "req_abc123",
  "errors": [
    {
      "field": "name",
      "code": "required",
      "message": "Invalid input: expected string, received undefined"
    },
    {
      "field": "email",
      "code": "invalid_format",
      "message": "Invalid email address"
    },
    {
      "field": "age",
      "code": "invalid_type",
      "message": "Invalid input: expected number, received string"
    }
  ]
}

{
  "type": "https://docs.appstrate.dev/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "Insufficient permissions",
  "code": "forbidden",
  "request_id": "req_abc123"
}
{
  "type": "https://docs.appstrate.dev/errors/not-found",
  "title": "Not Found",
  "status": 404,
  "detail": "Resource not found",
  "code": "not_found",
  "request_id": "req_abc123"
}
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "instance": "string",
  "code": "string",
  "request_id": "string",
  "param": "string",
  "retry_after": 0,
  "errors": [
    {
      "field": "string",
      "code": "string",
      "message": "string",
      "title": "string",
      "line": 1,
      "column": 1,
      "candidate_connections": [
        {
          "id": "string",
          "label": "string",
          "account_id": "string",
          "owned_by_actor": true,
          "needs_reconnection": true,
          "scopes_granted": [
            "string"
          ],
          "missing_scopes": [
            "string"
          ]
        }
      ],
      "connection_id": "string",
      "missing_scopes": [
        "string"
      ],
      "remedy": "new_connection",
      "owned_by_actor": true,
      "required_scopes": [
        "string"
      ],
      "auth_key": "string",
      "required_auth_key": "string",
      "available_auth_keys": [
        "string"
      ],
      "source": "admin_pin",
      "connect_url": "http://example.com",
      "expiresAt": "2019-08-24T14:15:22Z",
      "packageId": "string"
    }
  ]
}
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "instance": "string",
  "code": "string",
  "request_id": "string",
  "param": "string",
  "retry_after": 0,
  "errors": [
    {
      "field": "string",
      "code": "string",
      "message": "string",
      "title": "string",
      "line": 1,
      "column": 1,
      "candidate_connections": [
        {
          "id": "string",
          "label": "string",
          "account_id": "string",
          "owned_by_actor": true,
          "needs_reconnection": true,
          "scopes_granted": [
            "string"
          ],
          "missing_scopes": [
            "string"
          ]
        }
      ],
      "connection_id": "string",
      "missing_scopes": [
        "string"
      ],
      "remedy": "new_connection",
      "owned_by_actor": true,
      "required_scopes": [
        "string"
      ],
      "auth_key": "string",
      "required_auth_key": "string",
      "available_auth_keys": [
        "string"
      ],
      "source": "admin_pin",
      "connect_url": "http://example.com",
      "expiresAt": "2019-08-24T14:15:22Z",
      "packageId": "string"
    }
  ],
  "grant_may_be_redeemed": true
}
{
  "type": "https://docs.appstrate.dev/errors/connect-unavailable",
  "title": "Service Unavailable",
  "status": 503,
  "detail": "This connection method is unavailable on this deployment. Contact your administrator.",
  "code": "connect_unavailable",
  "request_id": "req_abc123"
}
{
  "type": "https://docs.appstrate.dev/errors/timeout",
  "title": "Gateway Timeout",
  "status": 504,
  "detail": "The connection attempt timed out after 60000ms — the login did not complete in time. Please try again.",
  "code": "timeout",
  "request_id": "req_def456"
}