V2
Upsert a User
Endpoint facilitating the programatic upsertion of a user. Users must be upserted 1 at a time. Events created for this user are for historical tracking purposes. Any event tied to a user through this endpoint will not trigger a study through Sprig’s SDK. Attributes and attribute values can be created and tied to a user through this endpoint.
POST
/
v2
/
users
Upsert a User
curl --request POST \
--url https://api.sprig.com/v2/users \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"attributes": {
"customer": "true"
},
"email": "user@test.com",
"events": [
{
"event": "login",
"timestamp": 1626448859836
}
],
"userId": "12347"
}
'import requests
url = "https://api.sprig.com/v2/users"
payload = {
"attributes": { "customer": "true" },
"email": "user@test.com",
"events": [
{
"event": "login",
"timestamp": 1626448859836
}
],
"userId": "12347"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
attributes: {customer: 'true'},
email: 'user@test.com',
events: [{event: 'login', timestamp: 1626448859836}],
userId: '12347'
})
};
fetch('https://api.sprig.com/v2/users', 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://api.sprig.com/v2/users",
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' => [
'customer' => 'true'
],
'email' => 'user@test.com',
'events' => [
[
'event' => 'login',
'timestamp' => 1626448859836
]
],
'userId' => '12347'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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://api.sprig.com/v2/users"
payload := strings.NewReader("{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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://api.sprig.com/v2/users")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sprig.com/v2/users")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}"
response = http.request(request)
puts response.read_body{
"error": "<string>"
}Headers
API-Key YOUR_API_KEY
Body
application/json
Post the necessary fields for the API to upsert a new user.
Response
Accepted
Was this page helpful?
⌘I
Upsert a User
curl --request POST \
--url https://api.sprig.com/v2/users \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"attributes": {
"customer": "true"
},
"email": "user@test.com",
"events": [
{
"event": "login",
"timestamp": 1626448859836
}
],
"userId": "12347"
}
'import requests
url = "https://api.sprig.com/v2/users"
payload = {
"attributes": { "customer": "true" },
"email": "user@test.com",
"events": [
{
"event": "login",
"timestamp": 1626448859836
}
],
"userId": "12347"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
attributes: {customer: 'true'},
email: 'user@test.com',
events: [{event: 'login', timestamp: 1626448859836}],
userId: '12347'
})
};
fetch('https://api.sprig.com/v2/users', 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://api.sprig.com/v2/users",
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' => [
'customer' => 'true'
],
'email' => 'user@test.com',
'events' => [
[
'event' => 'login',
'timestamp' => 1626448859836
]
],
'userId' => '12347'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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://api.sprig.com/v2/users"
payload := strings.NewReader("{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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://api.sprig.com/v2/users")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sprig.com/v2/users")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributes\": {\n \"customer\": \"true\"\n },\n \"email\": \"user@test.com\",\n \"events\": [\n {\n \"event\": \"login\",\n \"timestamp\": 1626448859836\n }\n ],\n \"userId\": \"12347\"\n}"
response = http.request(request)
puts response.read_body{
"error": "<string>"
}