# Log User Interaction POST /api/v1/metrics/interact/ Content-Type: application/json Record a user interaction with a resource and get updated state Reference: https://docs.aisquare.studio/api-reference/ai-square-studio-api/metrics/interact-create ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: AISquare Studio API version: 1.0.0 paths: /api/v1/metrics/interact/: post: operationId: interact-create summary: Log User Interaction description: Record a user interaction with a resource and get updated state tags: - subpackage_metrics responses: '200': description: Interaction recorded successfully content: application/json: schema: $ref: '#/components/schemas/metrics_interactCreate_Response_200' '400': description: Invalid request data content: application/json: schema: description: Any type '401': description: Authentication required content: application/json: schema: description: Any type '404': description: Resource not found content: application/json: schema: description: Any type requestBody: content: application/json: schema: $ref: '#/components/schemas/InteractionRequest' components: schemas: MetricsResourceTypeEnum: type: string enum: - quest - ai_note - ai_expert - podcast - collection - publication - ai_video - profile description: |- * `quest` - Quest * `ai_note` - AI Note * `ai_expert` - AI Expert * `podcast` - Podcast * `collection` - Collection * `publication` - Publication * `ai_video` - AI Video * `profile` - Profile title: MetricsResourceTypeEnum InteractionTypeEnum: type: string enum: - view - like - unlike - share - bookmark - unbookmark - comment description: |- * `view` - View * `like` - Like * `unlike` - Unlike * `share` - Share * `bookmark` - Bookmark * `unbookmark` - Unbookmark * `comment` - Comment title: InteractionTypeEnum InteractionRequest: type: object properties: resource_type: $ref: '#/components/schemas/MetricsResourceTypeEnum' resource_id: type: integer interaction_type: $ref: '#/components/schemas/InteractionTypeEnum' required: - resource_type - resource_id - interaction_type description: Serializer for interaction requests title: InteractionRequest metrics_interactCreate_Response_200: type: object properties: {} description: Empty response body title: metrics_interactCreate_Response_200 ``` ## SDK Code Examples ```python Bookmark an AI note import requests url = "https://api.example.com/api/v1/metrics/interact/" payload = { "resource_type": "ai_note", "resource_id": 15, "interaction_type": "bookmark" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Bookmark an AI note const url = 'https://api.example.com/api/v1/metrics/interact/'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"resource_type":"ai_note","resource_id":15,"interaction_type":"bookmark"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Bookmark an AI note package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/api/v1/metrics/interact/" payload := strings.NewReader("{\n \"resource_type\": \"ai_note\",\n \"resource_id\": 15,\n \"interaction_type\": \"bookmark\"\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(res) fmt.Println(string(body)) } ``` ```ruby Bookmark an AI note require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/metrics/interact/") 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 \"resource_type\": \"ai_note\",\n \"resource_id\": 15,\n \"interaction_type\": \"bookmark\"\n}" response = http.request(request) puts response.read_body ``` ```java Bookmark an AI note import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/api/v1/metrics/interact/") .header("Content-Type", "application/json") .body("{\n \"resource_type\": \"ai_note\",\n \"resource_id\": 15,\n \"interaction_type\": \"bookmark\"\n}") .asString(); ``` ```php Bookmark an AI note request('POST', 'https://api.example.com/api/v1/metrics/interact/', [ 'body' => '{ "resource_type": "ai_note", "resource_id": 15, "interaction_type": "bookmark" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Bookmark an AI note using RestSharp; var client = new RestClient("https://api.example.com/api/v1/metrics/interact/"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"resource_type\": \"ai_note\",\n \"resource_id\": 15,\n \"interaction_type\": \"bookmark\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Bookmark an AI note import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "resource_type": "ai_note", "resource_id": 15, "interaction_type": "bookmark" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/metrics/interact/")! 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() ``` ```python Record a view import requests url = "https://api.example.com/api/v1/metrics/interact/" payload = { "resource_type": "ai_expert", "resource_id": 7, "interaction_type": "view" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Record a view const url = 'https://api.example.com/api/v1/metrics/interact/'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"resource_type":"ai_expert","resource_id":7,"interaction_type":"view"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Record a view package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/api/v1/metrics/interact/" payload := strings.NewReader("{\n \"resource_type\": \"ai_expert\",\n \"resource_id\": 7,\n \"interaction_type\": \"view\"\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(res) fmt.Println(string(body)) } ``` ```ruby Record a view require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/metrics/interact/") 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 \"resource_type\": \"ai_expert\",\n \"resource_id\": 7,\n \"interaction_type\": \"view\"\n}" response = http.request(request) puts response.read_body ``` ```java Record a view import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/api/v1/metrics/interact/") .header("Content-Type", "application/json") .body("{\n \"resource_type\": \"ai_expert\",\n \"resource_id\": 7,\n \"interaction_type\": \"view\"\n}") .asString(); ``` ```php Record a view request('POST', 'https://api.example.com/api/v1/metrics/interact/', [ 'body' => '{ "resource_type": "ai_expert", "resource_id": 7, "interaction_type": "view" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Record a view using RestSharp; var client = new RestClient("https://api.example.com/api/v1/metrics/interact/"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"resource_type\": \"ai_expert\",\n \"resource_id\": 7,\n \"interaction_type\": \"view\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Record a view import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "resource_type": "ai_expert", "resource_id": 7, "interaction_type": "view" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/metrics/interact/")! 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() ``` ```python import requests url = "https://api.example.com/api/v1/metrics/interact/" payload = { "resource_type": "quest", "resource_id": 42, "interaction_type": "like" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.example.com/api/v1/metrics/interact/'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"resource_type":"quest","resource_id":42,"interaction_type":"like"}' }; 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.example.com/api/v1/metrics/interact/" payload := strings.NewReader("{\n \"resource_type\": \"quest\",\n \"resource_id\": 42,\n \"interaction_type\": \"like\"\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(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/metrics/interact/") 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 \"resource_type\": \"quest\",\n \"resource_id\": 42,\n \"interaction_type\": \"like\"\n}" 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.example.com/api/v1/metrics/interact/") .header("Content-Type", "application/json") .body("{\n \"resource_type\": \"quest\",\n \"resource_id\": 42,\n \"interaction_type\": \"like\"\n}") .asString(); ``` ```php request('POST', 'https://api.example.com/api/v1/metrics/interact/', [ 'body' => '{ "resource_type": "quest", "resource_id": 42, "interaction_type": "like" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.example.com/api/v1/metrics/interact/"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"resource_type\": \"quest\",\n \"resource_id\": 42,\n \"interaction_type\": \"like\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "resource_type": "quest", "resource_id": 42, "interaction_type": "like" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/metrics/interact/")! 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() ```