> 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 # Upsert user POST https://api.schematichq.com/users Content-Type: application/json Reference: https://docs.schematichq.com/api-reference/companies/upsert-user ## Authentication - `X-Schematic-Api-Key` header (required) — API Key authentication via header ## Request ### Body (application/json) This endpoint expects an UpsertUserRequestBody. - `keys` (map from string to string, required) — See [Key Management](https://docs.schematichq.com/developer_resources/key_management) for more information - `companies` (list of map from string to string, optional, nullable) — Optionally specify companies using array of key/value pairs - `company` (map from string to string, optional, nullable) — Add user to this company. Takes priority over companies. For exhaustive list of companies, use companies - `company_id` (string, optional, nullable) — Add user to this company. Takes priority over company_ids. For exhaustive list of companies, use company_ids - `company_ids` (list of string, optional, nullable) — Optionally specify companies using Schematic company ID - `id` (string, optional, nullable) — If you know the Schematic ID, you can use that here instead of keys - `last_seen_at` (datetime, optional, nullable) - `name` (string, optional, nullable) - `remove_keys` (list of string, optional) — Names of keys to remove from the user. Removing a key the user does not have does nothing, and a user must keep at least one key. - `traits` (UpsertUserRequestBodyTraits, optional) — A map of trait names to trait values - `update_only` (boolean, optional, nullable) ## Response ### 200 OK - `data` (UserDetailResponseData, required) - `params` (UsersPostResponsesContentApplicationJsonSchemaParams, 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 ### UpsertUserRequestBodyTraits A map of trait names to trait values ### UserDetailResponseData - `company_memberships` (list of CompanyMembershipDetailResponseData, required) - `created_at` (datetime, required) - `entity_traits` (list of EntityTraitDetailResponseData, required) - `environment_id` (string, required) - `id` (string, required) - `keys` (list of EntityKeyDetailResponseData, required) - `name` (string, required) - `updated_at` (datetime, required) - `last_seen_at` (datetime, optional, nullable) - `traits` (UserDetailResponseDataTraits, optional) — A map of trait names to trait values ### UsersPostResponsesContentApplicationJsonSchemaParams Input parameters ### CompanyMembershipDetailResponseData - `company_id` (string, required) - `created_at` (datetime, required) - `id` (string, required) - `updated_at` (datetime, required) - `user_id` (string, required) - `company` (CompanyResponseData, optional) ### EntityTraitDetailResponseData - `created_at` (datetime, required) - `definition_id` (string, required) - `environment_id` (string, required) - `id` (string, required) - `updated_at` (datetime, required) - `value` (string, required) - `definition` (EntityTraitDefinitionResponseData, optional) ### EntityKeyDetailResponseData - `created_at` (datetime, required) - `definition_id` (string, required) - `entity_id` (string, required) - `entity_type` (enum, required) - Allowed values: `company`, `user` - `environment_id` (string, required) - `id` (string, required) - `key` (string, required) - `updated_at` (datetime, required) - `value` (string, required) - `definition` (EntityKeyDefinitionResponseData, optional) ### UserDetailResponseDataTraits A map of trait names to trait values ### 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) ### EntityTraitDefinitionResponseData - `created_at` (datetime, required) - `display_name` (string, required) - `entity_type` (enum, required) - Allowed values: `company`, `user` - `hierarchy` (list of string, required) - `id` (string, required) - `trait_type` (enum, required) - Allowed values: `boolean`, `currency`, `date`, `number`, `string`, `url` - `updated_at` (datetime, required) ### EntityKeyDefinitionResponseData - `created_at` (datetime, required) - `entity_type` (enum, required) - Allowed values: `company`, `user` - `id` (string, required) - `key` (string, required) - `updated_at` (datetime, required) ## Examples **Request** ```json {} ``` **Response** ```json { "data": { "company_memberships": [ { "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" } } ], "created_at": "2024-01-15T09:30:00Z", "entity_traits": [ { "created_at": "2024-01-15T09:30:00Z", "definition_id": "string", "environment_id": "string", "id": "string", "updated_at": "2024-01-15T09:30:00Z", "value": "string", "definition": { "created_at": "2024-01-15T09:30:00Z", "display_name": "string", "entity_type": "company", "hierarchy": [ "string" ], "id": "string", "trait_type": "boolean", "updated_at": "2024-01-15T09:30:00Z" } } ], "environment_id": "string", "id": "string", "keys": [ { "created_at": "2024-01-15T09:30:00Z", "definition_id": "string", "entity_id": "string", "entity_type": "company", "environment_id": "string", "id": "string", "key": "string", "updated_at": "2024-01-15T09:30:00Z", "value": "string", "definition": { "created_at": "2024-01-15T09:30:00Z", "entity_type": "company", "id": "string", "key": "string", "updated_at": "2024-01-15T09:30:00Z" } } ], "name": "string", "updated_at": "2024-01-15T09:30:00Z", "last_seen_at": "2024-01-15T09:30:00Z", "traits": {} }, "params": {} } ``` **SDK Code** ```python import requests url = "https://api.schematichq.com/users" payload = {} headers = { "X-Schematic-Api-Key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.schematichq.com/users'; const options = { method: 'POST', headers: {'X-Schematic-Api-Key': '', 'Content-Type': 'application/json'}, body: '{}' }; 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/users" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Schematic-Api-Key", "") 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/users") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["X-Schematic-Api-Key"] = '' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.schematichq.com/users") .header("X-Schematic-Api-Key", "") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('POST', 'https://api.schematichq.com/users', [ 'body' => '{}', 'headers' => [ 'Content-Type' => 'application/json', 'X-Schematic-Api-Key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.schematichq.com/users"); var request = new RestRequest(Method.POST); request.AddHeader("X-Schematic-Api-Key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "X-Schematic-Api-Key": "", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.schematichq.com/users")! 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() ```