Skip to main content
POST
/
api
/
v1
/
client
/
{workspaceId}
/
user
Create or Identify User
curl --request POST \
  --url https://{baseurl}/api/v1/client/{workspaceId}/user \
  --header 'Content-Type: application/json' \
  --data '
{
  "attributes": {
    "plan": "free"
  },
  "userId": "hello-user"
}
'
import requests

url = "https://{baseurl}/api/v1/client/{workspaceId}/user"

payload = {
    "attributes": { "plan": "free" },
    "userId": "hello-user"
}
headers = {"Content-Type": "application/json"}

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

print(response.text)
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({attributes: {plan: 'free'}, userId: 'hello-user'})
};

fetch('https://{baseurl}/api/v1/client/{workspaceId}/user', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://{baseurl}/api/v1/client/{workspaceId}/user",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'attributes' => [
        'plan' => 'free'
    ],
    'userId' => 'hello-user'
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

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

func main() {

	url := "https://{baseurl}/api/v1/client/{workspaceId}/user"

	payload := strings.NewReader("{\n  \"attributes\": {\n    \"plan\": \"free\"\n  },\n  \"userId\": \"hello-user\"\n}")

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

	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://{baseurl}/api/v1/client/{workspaceId}/user")
  .header("Content-Type", "application/json")
  .body("{\n  \"attributes\": {\n    \"plan\": \"free\"\n  },\n  \"userId\": \"hello-user\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://{baseurl}/api/v1/client/{workspaceId}/user")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"attributes\": {\n    \"plan\": \"free\"\n  },\n  \"userId\": \"hello-user\"\n}"

response = http.request(request)
puts response.read_body
{
  "data": {
    "state": {
      "data": {
        "displays": [
          {
            "createdAt": "2025-02-03T11:23:13.050Z",
            "surveyId": "cm6orqtdd000a19wjhnbces5s"
          }
        ],
        "lastDisplayAt": "2025-02-03T11:23:13.050Z",
        "responses": [
          "cm6orqtdd000a19wjhnbces5s"
        ],
        "segments": [
          "cm6onrezn000hw2ahcokiz41v"
        ],
        "userId": "hello-user"
      },
      "expiresAt": "2025-02-03T11:23:13.050Z"
    }
  }
}
{
  "code": "bad_request",
  "message": "userId is required"
}
{
  "code": "not_found",
  "details": {
    "resource_id": "f16ttdvtkx85k5m4s561ruqj",
    "resource_type": "Environment"
  },
  "message": "Environment not found"
}
{
  "code": "internal_server_error",
  "details": {},
  "message": "An unexpected error occurred"
}

Path Parameters

workspaceId
string
required

Body

application/json

The body is of type object.

Response

OK

data
object