# Retrieve and Update User Activity PUT /api/v1/activity/{id}/ Content-Type: application/json Retrieves or updates a specific user activity. Reference: https://docs.aisquare.studio/api-reference/ai-square-studio-api/activity/retrieve ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: AISquare Studio API version: 1.0.0 paths: /api/v1/activity/{id}/: put: operationId: update summary: Retrieve and Update User Activity description: Retrieves or updates a specific user activity. tags: - subpackage_activity parameters: - name: id in: path required: true schema: type: integer responses: '200': description: User activity details content: application/json: schema: $ref: '#/components/schemas/UserActivity' '401': description: Unauthorized content: application/json: schema: description: Any type '404': description: Activity not found content: application/json: schema: description: Any type requestBody: content: application/json: schema: $ref: '#/components/schemas/UserActivity' components: schemas: ActivityTypeEnum: type: string enum: - '100' - '101' - '200' - '201' - '202' - '203' - '204' - '205' - '250' - '300' - '301' - '400' - '500' - '501' - '502' - '503' - '504' - '505' - '506' - '507' - '508' - '509' - '600' - '601' - '602' - '603' - '604' - '605' - '606' - '700' - '701' - '702' - '703' - '750' - '751' - '752' - '753' - '754' - '755' - '756' - '757' - '800' - '801' - '802' - '803' - '804' - '805' - '806' - '900' - '901' - '902' - '903' - '904' - '905' - '906' - '907' - '908' - '909' - '910' - '911' - '912' - '913' - '1000' - '1001' - '1002' - '1003' - '1004' - '1050' - '1051' - '1052' - '1053' - '1054' - '1055' - '1100' - '1101' - '1102' - '1103' - '1104' - '1400' - '1401' - '1402' - '1403' - '1404' - '1405' - '1406' - '1200' - '1201' - '1202' - '1300' - '1301' - '1302' description: |- * `100` - User Login * `101` - User Logout * `200` - Game Created * `201` - Game Joined * `202` - Game Left * `203` - Game Started * `204` - Game Completed * `205` - Game Won * `250` - Daily Streak * `300` - Elo Gained * `301` - Elo Lost * `400` - XP Gained * `500` - Resource Viewed * `501` - Resource Liked * `502` - Resource Unliked * `503` - Resource Shared * `504` - Resource Bookmarked * `505` - Resource Unbookmarked * `506` - Resource Commented * `507` - Resource Created * `508` - Resource Updated * `509` - Resource Deleted * `600` - Quest Created * `601` - Quest Viewed * `602` - Quest Updated * `603` - Quest Deleted * `604` - Quest Played * `605` - Quest Completed * `606` - Quest Leaderboard Viewed * `700` - Publication Created * `701` - Publication Viewed * `702` - Publication Updated * `703` - Publication Deleted * `750` - Blog Created * `751` - Blog Viewed * `752` - Blog Read * `753` - Blog Updated * `754` - Blog Deleted * `755` - Blog Bookmarked * `756` - Blog Unbookmarked * `757` - Blog Previewed * `800` - Experience Created * `801` - Experience Viewed * `802` - Experience Updated * `803` - Experience Deleted * `804` - Experience Published * `805` - Experience Autofilled * `806` - Experience Bulk Deleted * `900` - AI Domain Created * `901` - AI Domain Viewed * `902` - AI Domain Updated * `903` - AI Domain Deleted * `904` - AI Domain Saved * `905` - AI Question Generated * `906` - AI Answer Generated * `907` - AI Explanation Generated * `908` - AI Checker Generated * `909` - AI Options Generated * `910` - AI Chat Started * `911` - AI Chat Message Sent * `912` - AI Domain Knowledge Rebuilt * `913` - AI Knowledge Searched * `1000` - Podcast Created * `1001` - Podcast Viewed * `1002` - Podcast Listened * `1003` - Podcast Updated * `1004` - Podcast Deleted * `1050` - Video Created * `1051` - Video Viewed * `1052` - Video Updated * `1053` - Video Deleted * `1054` - Video Published * `1055` - Video Regenerated * `1100` - Content Document Created * `1101` - Content Document Viewed * `1102` - Content Document Updated * `1103` - Content Document Deleted * `1104` - Content Document Reprocessed * `1400` - Collection Created * `1401` - Collection Viewed * `1402` - Collection Updated * `1403` - Collection Deleted * `1404` - Collection Experience Added * `1405` - Collection Experience Removed * `1406` - Collection Experience Reordered * `1200` - Profile Updated * `1201` - Profile Picture Updated * `1202` - Profile Viewed * `1300` - User Followed * `1301` - User Unfollowed * `1302` - User Profile Visited title: ActivityTypeEnum UserSimple: type: object properties: id: type: integer username: type: string description: >- Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. email: type: string format: email full_name: type: string first_time_login: type: boolean description: Check if this is the user's first login. theme: type: - string - 'null' is_superuser: type: boolean description: >- Designates that this user has all permissions without explicitly assigning them. is_staff: type: boolean description: Designates whether the user can log into this admin site. is_active: type: boolean description: >- Designates whether this user should be treated as active. Unselect this instead of deleting accounts. is_verified: type: boolean profile_picture: type: string format: uri description: |- Convert ImageFieldFile to URL string for JSON serialization. Args: obj: The model instance being serialized (typically IAMUser) Returns: str | None: The URL of the profile picture, or None if not available required: - id - username - email - first_time_login - profile_picture description: >- Mixin to handle profile_picture serialization for WebSocket compatibility. This mixin adds a SerializerMethodField for profile_picture that converts ImageFieldFile objects to URL strings, making them JSON serializable for WebSocket consumers. The mixin intelligently handles profile pictures from IAMUserDetail by: 1. Accessing the related `details` queryset on the IAMUser model 2. Extracting the ImageFieldFile from the first detail record 3. Converting it to a URL string for JSON serialization Usage: ```python class MyUserSerializer(ProfilePictureMixin, serializers.ModelSerializer): class Meta: model = User fields = ['id', 'username', 'profile_picture', ...] ``` Note: - This mixin expects the model to have a `details` related manager - The related detail should have a `profile_picture` ImageField - Returns None if no profile picture is found or an error occurs title: UserSimple UserActivity: type: object properties: id: type: integer activity_type: $ref: '#/components/schemas/ActivityTypeEnum' user: $ref: '#/components/schemas/UserSimple' workspace_group_id: type: integer uid: type: string format: uuid created_at: type: string format: date-time updated_at: type: string format: date-time deleted_at: type: - string - 'null' format: date-time is_active: type: boolean created_by: type: - string - 'null' updated_by: type: - string - 'null' deleted_by: type: - string - 'null' text: type: string resource: oneOf: - description: Any type - type: 'null' workspace_group: type: - integer - 'null' description: >- Workspace group this activity belongs to (derived from user personal workspace or resource context) required: - id - user - workspace_group_id - uid - created_at - updated_at - text title: UserActivity ``` ## SDK Code Examples ```python import requests url = "https://api.example.com/api/v1/activity/1/" payload = { "user": { "username": "johndoe", "email": "johndoe@example.com" }, "text": "User logged in successfully from IP 192.168.1.10" } headers = {"Content-Type": "application/json"} response = requests.put(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.example.com/api/v1/activity/1/'; const options = { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: '{"user":{"username":"johndoe","email":"johndoe@example.com"},"text":"User logged in successfully from IP 192.168.1.10"}' }; 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/activity/1/" payload := strings.NewReader("{\n \"user\": {\n \"username\": \"johndoe\",\n \"email\": \"johndoe@example.com\"\n },\n \"text\": \"User logged in successfully from IP 192.168.1.10\"\n}") req, _ := http.NewRequest("PUT", 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/activity/1/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Put.new(url) request["Content-Type"] = 'application/json' request.body = "{\n \"user\": {\n \"username\": \"johndoe\",\n \"email\": \"johndoe@example.com\"\n },\n \"text\": \"User logged in successfully from IP 192.168.1.10\"\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.put("https://api.example.com/api/v1/activity/1/") .header("Content-Type", "application/json") .body("{\n \"user\": {\n \"username\": \"johndoe\",\n \"email\": \"johndoe@example.com\"\n },\n \"text\": \"User logged in successfully from IP 192.168.1.10\"\n}") .asString(); ``` ```php request('PUT', 'https://api.example.com/api/v1/activity/1/', [ 'body' => '{ "user": { "username": "johndoe", "email": "johndoe@example.com" }, "text": "User logged in successfully from IP 192.168.1.10" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.example.com/api/v1/activity/1/"); var request = new RestRequest(Method.PUT); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"user\": {\n \"username\": \"johndoe\",\n \"email\": \"johndoe@example.com\"\n },\n \"text\": \"User logged in successfully from IP 192.168.1.10\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "user": [ "username": "johndoe", "email": "johndoe@example.com" ], "text": "User logged in successfully from IP 192.168.1.10" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/activity/1/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PUT" 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() ```