Skip to main content
POST
/
api
/
church
/
createchurch
/
:pastorId
Create Church
curl --request POST \
  --url https://api.example.com/api/church/createchurch/:pastorId \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "address": "<string>",
  "supportcontact": {
    "supportcontact.phone": "<string>",
    "supportcontact.email": "<string>",
    "supportcontact.website": "<string>"
  }
}
'
{
  "success": true,
  "message": "<string>",
  "data": {
    "data._id": "<string>",
    "data.name": "<string>",
    "data.address": "<string>",
    "data.supportcontact": {},
    "data.pastor": {},
    "data.members": [
      {}
    ]
  }
}

Authentication

This endpoint requires:
  • Valid JWT token in the Authorization header
  • User role must be pastor

Endpoint

POST /api/church/createchurch/:pastorId

Path Parameters

pastorId
string
required
The MongoDB ObjectId of the pastor creating the church. This should match the authenticated user’s profile ID.

Request Body

name
string
required
The name of the church. Must be unique across all churches in the system.
address
string
required
The physical address of the church.
supportcontact
object
required
Contact information for church support.
supportcontact.phone
string
required
Church support telephone number.
supportcontact.email
string
required
Church support email address. Must be a valid email format and will be converted to lowercase.
supportcontact.website
string
Church website URL (optional).

Response

success
boolean
Indicates whether the church creation was successful.
message
string
A descriptive message about the operation result.
data
object
The created church object with populated pastor and member details.
data._id
string
The unique MongoDB ObjectId of the created church.
data.name
string
The name of the church.
data.address
string
The physical address of the church.
data.supportcontact
object
Contact information object containing phone, email, and optional website.
data.pastor
object
Populated pastor profile object (excludes sensitive fields like password).
data.members
array
Array of member profile objects. The pastor is automatically added as the first member.

Example Request

curl -X POST https://api.example.com/api/church/createchurch/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Grace Community Church",
    "address": "123 Main Street, Springfield, IL 62701",
    "supportcontact": {
      "phone": "+1-555-123-4567",
      "email": "[email protected]",
      "website": "https://gracechurch.org"
    }
  }'

Example Response

Success (201 Created)

{
  "success": true,
  "message": "Church Created",
  "data": {
    "_id": "507f191e810c19729de860ea",
    "name": "Grace Community Church",
    "address": "123 Main Street, Springfield, IL 62701",
    "supportcontact": {
      "phone": "+1-555-123-4567",
      "email": "[email protected]",
      "website": "https://gracechurch.org"
    },
    "pastor": {
      "name": "John Smith",
      "phoneNumber": "+1-555-987-6543",
      "authDetails": {
        "email": "[email protected]",
        "role": "pastor"
      }
    },
    "members": [
      {
        "name": "John Smith",
        "phoneNumber": "+1-555-987-6543",
        "authDetails": {
          "email": "[email protected]",
          "role": "pastor"
        }
      }
    ]
  }
}

Church Name Already Exists (200 OK)

{
  "success": false,
  "message": "Church Name Already exists",
  "data": {
    "_id": "507f191e810c19729de860ea",
    "name": "Grace Community Church",
    "address": "123 Main Street, Springfield, IL 62701",
    "supportcontact": {
      "phone": "+1-555-123-4567",
      "email": "[email protected]"
    },
    "pastor": {},
    "members": []
  }
}

Unauthorized - Not a Pastor (403 Forbidden)

{
  "success": false,
  "message": "Access Denied",
  "data": "The role 'member' is not allowed for this route"
}

Server Error (500 Internal Server Error)

{
  "success": false,
  "message": "Church Creation not successful",
  "data": "Validation error message or server error details"
}

Notes

  • The pastor creating the church is automatically added to the members array
  • Church names must be unique across the entire system
  • Email addresses are automatically converted to lowercase
  • The response includes fully populated pastor and member objects with auth details (excluding passwords)
  • The endpoint validates that the user has the pastor role before allowing church creation

Build docs developers (and LLMs) love