> If you are setting up, configuring, or answering questions about Schematic, connect the
> Schematic MCP server before working from these pages. It reads and writes plans, features,
> entitlements, and overrides against the real account, so what you report and what you build
> match what actually exists.
>
> The server is at https://api.schematichq.com/mcp
>
> From Claude, ChatGPT, or another chat assistant, add it as a custom connector:
> https://docs.schematichq.com/working-with-ai
>
> From a coding assistant such as Claude Code, Codex, or Cursor:
> https://docs.schematichq.com/building-with-ai
>
> For clean Markdown of any page, append `.md` to the page URL. For a complete page index,
> see https://docs.schematichq.com/llms.txt

# Get or create company membership

POST https://api.schematichq.com/company-memberships
Content-Type: application/json

Reference: https://docs.schematichq.com/api-reference/companies/get-or-create-company-membership

## Authentication

- `X-Schematic-Api-Key` header (required) — API Key authentication via header

## Request

### Body (application/json)

This endpoint expects a GetOrCreateCompanyMembershipRequestBody.

- `company_id` (string, required)
- `user_id` (string, required)

## Response

### 200

OK

- `data` (CompanyMembershipDetailResponseData, required)
- `params` (CompanyMembershipsPostResponsesContentApplicationJsonSchemaParams, required) — Input parameters

## Errors

### 400 Bad Request Error

Bad request

- `error` (string, required) — Error message

### 401 Unauthorized Error

Unauthorized

- `error` (string, required) — Error message

### 403 Forbidden Error

Forbidden

- `error` (string, required) — Error message

### 404 Not Found Error

Not found

- `error` (string, required) — Error message

### 500 Internal Server Error

Server error

- `error` (string, required) — Error message

## Types

### CompanyMembershipDetailResponseData

- `company_id` (string, required)
- `created_at` (datetime, required)
- `id` (string, required)
- `updated_at` (datetime, required)
- `user_id` (string, required)
- `company` (CompanyResponseData, optional)

### CompanyMembershipsPostResponsesContentApplicationJsonSchemaParams

Input parameters

### CompanyResponseData

- `created_at` (datetime, required)
- `environment_id` (string, required)
- `id` (string, required)
- `name` (string, required)
- `updated_at` (datetime, required)
- `last_seen_at` (datetime, optional, nullable)
- `logo_url` (string, optional, nullable)

## Examples

**Request**

```json
{
  "company_id": "string",
  "user_id": "string"
}
```

**Response**

```json
{
  "data": {
    "company_id": "string",
    "created_at": "2024-01-15T09:30:00Z",
    "id": "string",
    "updated_at": "2024-01-15T09:30:00Z",
    "user_id": "string",
    "company": {
      "created_at": "2024-01-15T09:30:00Z",
      "environment_id": "string",
      "id": "string",
      "name": "string",
      "updated_at": "2024-01-15T09:30:00Z",
      "last_seen_at": "2024-01-15T09:30:00Z",
      "logo_url": "string"
    }
  },
  "params": {}
}
```

**SDK Code**

```python
import requests

url = "https://api.schematichq.com/company-memberships"

payload = {
    "company_id": "string",
    "user_id": "string"
}
headers = {
    "X-Schematic-Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.schematichq.com/company-memberships';
const options = {
  method: 'POST',
  headers: {'X-Schematic-Api-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"company_id":"string","user_id":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.schematichq.com/company-memberships"

	payload := strings.NewReader("{\n  \"company_id\": \"string\",\n  \"user_id\": \"string\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Schematic-Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.schematichq.com/company-memberships")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Schematic-Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"company_id\": \"string\",\n  \"user_id\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.schematichq.com/company-memberships")
  .header("X-Schematic-Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"company_id\": \"string\",\n  \"user_id\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.schematichq.com/company-memberships', [
  'body' => '{
  "company_id": "string",
  "user_id": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Schematic-Api-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.schematichq.com/company-memberships");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Schematic-Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"company_id\": \"string\",\n  \"user_id\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Schematic-Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "company_id": "string",
  "user_id": "string"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.schematichq.com/company-memberships")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```