### CreateInstallation Request Example Source: https://developer.safetyculture.com/reference/partnerintegrationservice_createinstallation This snippet shows an example of a request body for the CreateInstallation method. It includes the necessary parameters for installing an application. ```json { "app_id": "string", "name": "string", "configuration": { "key": "value" } } ``` -------------------------------- ### CreateInstallation Response Example Source: https://developer.safetyculture.com/reference/partnerintegrationservice_createinstallation This snippet shows an example of a successful response from the CreateInstallation method, including the unique identifier for the new app installation. ```json { "installation_id": "string" } ``` -------------------------------- ### Get Installation OpenAPI Definition Source: https://developer.safetyculture.com/reference/partnerintegrationservice_getinstallation This OpenAPI definition outlines the structure and parameters for the Get installation endpoint. ```json { "openapi": "3.1.0", "info": { "title": "SafetyCulture API", "version": "v1.307.65", "contact": { "name": "SafetyCulture Support", "url": "https://help.safetyculture.com", "email": "support@safetyculture.com" } }, "paths": { "/integrations/v1/apps/{app_id}/installations/{installation_id}": { "get": { "summary": "Get installation", "operationId": "PartnerIntegrationService_GetInstallation", "responses": { "200": { "description": "A successful response.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/s12.integrations.app.v1.GetInstallationResponse" } } } }, "default": { "description": "An unexpected error response.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/google.rpc.Status" } } } } }, "parameters": [ { "name": "app_id", "description": "The unique identifier for the app", "in": "path", "required": true, "schema": { "type": "string" } }, { "name": "installation_id", "description": "The unique identifier for the app installation", "in": "path", "required": true, "schema": { "type": "string" } } ], "tags": [ "Apps" ] } } }, "externalDocs": { "description": "How to generate an API Token", "url": "https://help.safetyculture.com/en-US/000007/" }, "servers": [ { "url": "https://api.safetyculture.io" } ], "components": { "schemas": { "google.protobuf.Any": { "type": "object", "properties": { "@type": { "type": "string", "description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\n the fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading "." is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics." } }, "additionalProperties": {} } } } } ``` -------------------------------- ### Get Installation Details Source: https://developer.safetyculture.com/reference/partnerintegrationservice_getinstallation Fetches the details of a specific app installation using its ID. ```APIDOC ## GET /v1/integrations/installations/{installation_id} ### Description Retrieves the details of a specific app installation. ### Method GET ### Endpoint /v1/integrations/installations/{installation_id} ### Parameters #### Path Parameters - **installation_id** (string) - Required - The ID of the installation to retrieve. ### Response #### Success Response (200) - **app_id** (string) - The ID of the app. - **app_name** (string) - The name of the application. - **installation_id** (string) - The ID of this installation. - **installation_configuration** (string) - The configuration of the installation. #### Response Example ```json { "app_id": "string", "app_name": "string", "installation_id": "string", "installation_configuration": "string" } ``` ``` -------------------------------- ### Install an app request Source: https://developer.safetyculture.com/docs/create-and-install-apps-in-safetyculture Use the Create installation API to install a registered app. Include the unique app_id in the URL path. Each app can only be installed once. ```curl curl --request POST \ --url https://api.safetyculture.io/integrations/v1/apps/YOUR_APP_UNIQUE_ID/installations \ --header 'accept: application/json' \ --header 'authorization: Bearer YOUR_API_TOKEN_GOES_HERE' \ --header 'content-type: application/json' ``` -------------------------------- ### Create Installation Source: https://developer.safetyculture.com/reference/partnerintegrationservice_createinstallation Creates a new installation for a partner integration. This operation requires authentication and returns the unique identifier of the newly created installation. ```APIDOC ## POST /integrations/app/v1/installations ### Description Creates a new installation for a partner integration. ### Method POST ### Endpoint /integrations/app/v1/installations ### Request Body - **installation_id** (string) - Required - The unique identifier for the app installation ### Response #### Success Response (200) - **installation_id** (string) - The unique identifier for the app installation ``` -------------------------------- ### Create Installation Source: https://developer.safetyculture.com/reference/partnerintegrationservice_createinstallation This endpoint is used to install an existing application in your organization. It requires specific permissions and a registered partner account. ```APIDOC ## POST /integrations/v1/apps/{app_id}/installations ### Description Installs an existing application in your organization. ### Method POST ### Endpoint /integrations/v1/apps/{app_id}/installations ### Parameters #### Path Parameters - **app_id** (string) - Required - The unique identifier for the app #### Request Body - **body** (object) - Required - The request body for creating an installation. Refer to `s12.integrations.app.v1.PartnerIntegrationService.CreateInstallationBody` for schema details. ### Response #### Success Response (200) - **response** (object) - Description: A successful response. Refer to `s12.integrations.app.v1.CreateInstallationResponse` for schema details. #### Error Response (default) - **error** (object) - Description: An unexpected error response. Refer to `google.rpc.Status` for schema details. ``` -------------------------------- ### Create Installation Source: https://developer.safetyculture.com/docs/create-and-install-apps-in-safetyculture Installs a previously registered application into the SafetyCulture organization. Each app can only be installed once. ```APIDOC ## POST /integrations/v1/apps/{app_id}/installations ### Description Installs a registered application into the SafetyCulture organization. An app can only be installed once. ### Method POST ### Endpoint https://api.safetyculture.io/integrations/v1/apps/{app_id}/installations ### Parameters #### Path Parameters - **app_id** (string) - Required - The unique identifier of the application to install. ### Response #### Success Response (200) - **installation_id** (string) - The unique identifier for the app installation. #### Response Example ```json { "installation_id": "YOUR_INSTALLATION_UNIQUE_ID" } ``` ``` -------------------------------- ### Install an app response Source: https://developer.safetyculture.com/docs/create-and-install-apps-in-safetyculture A successful app installation request returns a JSON object with the unique installation_id. ```json { "installation_id": "YOUR_INSTALLATION_UNIQUE_ID" } ``` -------------------------------- ### Schedule Recurrence RRULE Examples Source: https://developer.safetyculture.com/reference/schedulingservice_updateschedulerecurrence Provides examples of `dtstart_rrule` configurations using RRULE format, including UTC and timezone-specific examples. Supports weekly, monthly, and yearly frequencies with specific interval and day/month settings. ```text DTSTART:20240101T140000Z\nRRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR ``` ```text DTSTART;TZID=America/New_York:20240101T140000\nRRULE:FREQ=DAILY;INTERVAL=1 ``` -------------------------------- ### Protobuf Any Type - Go Example Source: https://developer.safetyculture.com/reference/documentspublicservice_getfolderchildren Demonstrates packing and unpacking a Protobuf message into an Any type using Go. ```go foo := &pb.Foo{...} any, err := ptypes.MarshalAny(foo) ... foo := &pb.Foo{} if err := ptypes.UnmarshalAny(any, foo); err != nil { ... } ``` -------------------------------- ### Start Inspection API Request Body Source: https://developer.safetyculture.com/reference/thepubservice_startinspection Example of a request body to start an inspection, pre-filling the 'Conducted on' date. ```json { "template": "template_id", "location": { "name": "Location Name" }, "audit_data": { "date_started": "2023-10-27T09:00:00Z" } } ``` -------------------------------- ### Add multiple users to multiple folders (sites) Source: https://developer.safetyculture.com/reference/directory_addusersfoldersassociations This is the most comprehensive example, showing how to add several users to several folders simultaneously. Ensure all provided IDs are accurate for successful assignment. ```shell curl -X POST "https://api.safetyculture.io/directory/v1/users/folders/membership" \ -H "Authorization: Bearer {api_token}" \ -d '{ "assignments": { "090ab7e0-2781-48cd-aeb2-752e5de47d75": { "user_ids": [ "6b0c862f-1649-4382-a0c6-ba063497a04c", "eeb88ebc-8304-4816-b484-5543558b4aba", "99f79e18-c2de-4b78-9e83-218f057dc24c" ] }, "3a943a96-124c-4d36-b224-17d53fda9243": { "user_ids": [ "6b0c862f-1649-4382-a0c6-ba063497a04c", "eeb88ebc-8304-4816-b484-5543558b4aba" ] } } }' ``` -------------------------------- ### Get Installation by App ID and Installation ID Source: https://developer.safetyculture.com/reference/partnerintegrationservice_getinstallation Retrieves the details of a specific application installation. You need to provide both the application's unique ID (`app_id`) and the installation's unique ID (`installation_id`). ```APIDOC ## GET /integrations/v1/apps/{app_id}/installations/{installation_id} ### Description Retrieves the details of a specific application installation. ### Method GET ### Endpoint /integrations/v1/apps/{app_id}/installations/{installation_id} ### Parameters #### Path Parameters - **app_id** (string) - Required - The unique identifier for the app - **installation_id** (string) - Required - The unique identifier for the app installation ### Response #### Success Response (200) - **installation** (object) - Contains the details of the app installation. - **name** (string) - The name of the installation. - **app_id** (string) - The unique identifier for the app. - **created_at** (string) - The timestamp when the installation was created. - **updated_at** (string) - The timestamp when the installation was last updated. - **created_by** (object) - Information about the user who created the installation. - **user_id** (string) - The unique identifier for the user. - **name** (string) - The name of the user. - **updated_by** (object) - Information about the user who last updated the installation. - **user_id** (string) - The unique identifier for the user. - **name** (string) - The name of the user. - **state** (string) - The current state of the installation (e.g., "active", "inactive"). - **metadata** (object) - Additional metadata associated with the installation. #### Response Example ```json { "installation": { "name": "Example Installation", "app_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z", "created_by": { "user_id": "user-123", "name": "John Doe" }, "updated_by": { "user_id": "user-123", "name": "John Doe" }, "state": "active", "metadata": { "key": "value" } } } ``` ``` -------------------------------- ### Example: Update Establishment Hours in Python Source: https://developer.safetyculture.com/reference/oshaservice_updateestablishmenthours A Python example demonstrating how to update establishment hours using the 'requests' library. Replace placeholders with your specific details. ```python import requests import json establishment_id = 'your_establishment_id' api_token = 'YOUR_API_TOKEN' api_url = f'https://your-api-domain.com/v1/establishments/{establishment_id}/hours' hours_data = { "hours_worked": [ { "year_of_filing": 2023, "month_of_filing": 1, "hours_worked": 160 }, { "year_of_filing": 2023, "month_of_filing": 2, "hours_worked": 150 } ] } headers = { 'Authorization': f'Bearer {api_token}', 'Content-Type': 'application/json' } response = requests.post(api_url, headers=headers, data=json.dumps(hours_data)) if response.status_code == 200: print('Success:', response.json()) else: print('Error:', response.status_code, response.text) ``` -------------------------------- ### Example Webhook Payload for Inspection Started Event Source: https://developer.safetyculture.com/reference/webhooks This JSON payload represents a notification triggered when an inspection has started. It includes details about the webhook, the event, and the affected resource. ```json { "webhook_id": "5378baaa-a470-48cc-8f11-ae2893551234", "version": "3.0.0", "event": { "date_triggered": "2023-07-11T23:04:24Z", "event_types": [ "TRIGGER_EVENT_INSPECTION", "TRIGGER_EVENT_INSPECTION_METADATA", "TRIGGER_EVENT_INSPECTION_HAS_STARTED" ], "triggered_by": { "user": "user_b0bc1fcbef1a4ecf9f9b3d2dbddb1234", "organization": "53465cd9-8933-4518-9b7e-c7a71b3b1234" } }, "resource": { "id": "audit_047ef3d184014ce7a04bc65701b51234", "type": "INSPECTION" }, "data": { "event": { "inspection_has_started": {} }, "details": { "inspection_id": "audit_047ef3d184014ce7a04bc65701b51234", "template_id": "template_5ac67d8738af471f9ad861232d8e1234", "org_id": "53465cd9-8933-4518-9b7e-c7a71b3b1234", "modify_time": "2022-05-10T05:24:56Z", "canonical_start_time": "2022-05-10T05:24:56Z", "score": {} } } } ``` -------------------------------- ### URL-Encoded Date/Time in GET Request Source: https://developer.safetyculture.com/reference/date-time-format When including date/time in a URL query parameter for a GET request, it must be URL-encoded. This example shows how to encode a date/time string for the `modified_after` parameter. ```shell curl --location 'https://api.safetyculture.io/tasks/v1/feed/issue_timeline_items?modified_after=2023-04-05T01%3A04%3A33.000Z' \ --header 'Authorization: Bearer {api_token}' ``` -------------------------------- ### Add multiple users to a folder (site) Source: https://developer.safetyculture.com/reference/directory_addusersfoldersassociations This example demonstrates how to assign multiple users to a single folder. Verify that all user IDs are valid and belong to the correct folder. ```shell curl -X POST "https://api.safetyculture.io/directory/v1/users/folders/membership" \ -H "Authorization: Bearer {api_token}" \ -d '{ "assignments": { "090ab7e0-2781-48cd-aeb2-752e5de47d75": { "user_ids": [ "6b0c862f-1649-4382-a0c6-ba063497a04c", "eeb88ebc-8304-4816-b484-5543558b4aba", "99f79e18-c2de-4b78-9e83-218f057dc24c" ] }, } }' ``` -------------------------------- ### Quiz Session Started Webhook Event Example Source: https://developer.safetyculture.com/reference/webhooks This JSON payload indicates that a quiz session has started or is available. It includes user and quiz identifiers, along with quiz title and user email. ```json { "webhook_id": "8475debb-a531-4fc6-b25f-eaeee6e75b82", "event": { "date_triggered": "2025-09-25T05:24:56Z", "event_types": ["TRIGGER_EVENT_TRAINING_QUIZ_SESSION_STARTED"], "triggered_by": { "user_type": "user", "user": "fd2a2355-da0f-499e-b7a6-4df5c4c89722", "organization": "fac4e871-cc83-403e-b1d7-007b5809f8e7" } }, "resource": { "id": "6850de8c8a2a0a3f31e53dac", "type": "QUIZ" }, "data": { "user_id": "fd2a2355-da0f-499e-b7a6-4df5c4c89722", "quiz_id": "6850de8c8a2a0a3f31e53dde", "email": "user@example.com", "quiz_title": "Safety Induction Quiz" } } ``` -------------------------------- ### List All Installations OpenAPI Definition Source: https://developer.safetyculture.com/reference/partnerintegrationservice_listinstallations This OpenAPI definition specifies the GET endpoint for listing all installations. It includes details on request parameters such as limit, app_id, and next_page_token, as well as response schemas for success and error cases. ```json { "openapi": "3.1.0", "info": { "title": "SafetyCulture API", "version": "v1.307.65", "contact": { "name": "SafetyCulture Support", "url": "https://help.safetyculture.com", "email": "support@safetyculture.com" } }, "paths": { "/integrations/v1/apps/installations": { "get": { "summary": "List all installations", "operationId": "PartnerIntegrationService_ListInstallations", "responses": { "200": { "description": "A successful response.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/s12.integrations.app.v1.ListInstallationsResponse" } } } }, "default": { "description": "An unexpected error response.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/google.rpc.Status" } } } } }, "parameters": [ { "name": "limit", "description": "Maximum number of entries to return.", "in": "query", "required": false, "schema": { "type": "integer", "format": "int32" } }, { "name": "app_id", "description": "Optional. If present, will filter by an application id", "in": "query", "required": false, "schema": { "type": "string" } }, { "name": "next_page_token", "description": "Optional. If present, then retrieve the next batch of results from the\npreceding call to this method. `page_token` must be the value of\n`next_page_token` from the previous response.", "in": "query", "required": false, "schema": { "type": "string" } } ], "tags": [ "Apps" ] } } }, "externalDocs": { "description": "How to generate an API Token", "url": "https://help.safetyculture.com/en-US/000007/" }, "servers": [ { "url": "https://api.safetyculture.io" } ], "components": { "schemas": { "google.protobuf.Any": { "type": "object", "properties": { "@type": { "type": "string", "description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\n the fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading "." is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics." } }, "additionalProperties": {}, ``` -------------------------------- ### Example: Update Establishment Hours in Node.js Source: https://developer.safetyculture.com/reference/oshaservice_updateestablishmenthours Shows how to update establishment hours using Node.js with the 'axios' library. Remember to set your API token and domain. ```javascript const axios = require('axios'); const establishmentId = 'your_establishment_id'; const apiToken = 'YOUR_API_TOKEN'; const apiUrl = `https://your-api-domain.com/v1/establishments/${establishmentId}/hours`; const hoursData = { "hours_worked": [ { "year_of_filing": 2023, "month_of_filing": 1, "hours_worked": 160 }, { "year_of_filing": 2023, "month_of_filing": 2, "hours_worked": 150 } ] }; axios.post(apiUrl, hoursData, { headers: { 'Authorization': `Bearer ${apiToken}`, 'Content-Type': 'application/json' } }) .then(response => { console.log('Success:', response.data); }) .catch(error => { console.error('Error:', error.response ? error.response.data : error.message); }); ``` -------------------------------- ### Example: Get File ID from URL Source: https://developer.safetyculture.com/reference/documentspublicservice_linkfiles Illustrates how to extract a `file_id` from a SafetyCulture web app document URL. ```text https://app.safetyculture.com/documents/document/765aa2e6-69cb-43b5-8ab4-48ab26e2a094 ``` -------------------------------- ### Any Message Packing and Unpacking Examples Source: https://developer.safetyculture.com/reference/inspectionservice_completeinspection Demonstrates how to pack and unpack arbitrary serialized protocol buffer messages using the Any type in different programming languages. This is useful for handling diverse data types within a unified structure. ```csharp Foo foo = ...; Any any; any.PackFrom(foo); ... if (any.UnpackTo(&foo)) { ... } ``` ```java Foo foo = ...; Any any = Any.pack(foo); ... if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } ``` ```python foo = Foo(...) any = Any() any.Pack(foo) ... if any.Is(Foo.DESCRIPTOR): any.Unpack(foo) ... ``` ```go foo := &pb.Foo{...} any, err := ptypes.MarshalAny(foo) ... foo := &pb.Foo{} if err := ptypes.UnmarshalAny(any, foo); err != nil { ... } ``` -------------------------------- ### Get Rapid Refresh by ID - Python Example Source: https://developer.safetyculture.com/reference/trainingrapidrefreshservice_getrapidrefreshbyid This Python example uses the 'requests' library to fetch a rapid refresh training by its ID. Remember to replace placeholders with your actual API token and the rapid refresh ID. ```python import requests api_url = 'https://api.safetyculture.com/training/rapid-refreshes/RAPID_REFRESH_ID' api_token = 'YOUR_API_TOKEN' headers = { 'Authorization': f'Bearer {api_token}' } try: response = requests.get(api_url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print(response.json()) except requests.exceptions.RequestException as e: print(f'Error fetching rapid refresh: {e}') ``` -------------------------------- ### Any Message Packing and Unpacking Examples Source: https://developer.safetyculture.com/reference/investigationsservice_listinvestigationactions Demonstrates how to pack and unpack arbitrary serialized protocol buffer messages using the Any type in various languages. The pack methods typically use 'type.googleapis.com/full.type.name' as the type URL. ```protobuf Example 1: Pack and unpack a message in C++. Foo foo = ...; Any any; any.PackFrom(foo); ... if (any.UnpackTo(&foo)) { ... } Example 2: Pack and unpack a message in Java. Foo foo = ...; Any any = Any.pack(foo); ... if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() any.Pack(foo) ... if any.Is(Foo.DESCRIPTOR): any.Unpack(foo) ... Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := ptypes.MarshalAny(foo) ... foo := &pb.Foo{} if err := ptypes.UnmarshalAny(any, foo); err != nil { ... } ``` -------------------------------- ### Example: Get Entity ID from URL Source: https://developer.safetyculture.com/reference/documentspublicservice_linkfiles Illustrates how to extract an `entity_id` from a SafetyCulture web app entity URL, such as an asset. ```text https://app.safetyculture.com/assets/765aa2e6-69cb-43b5-8ab4-48ab26e2a094 ``` -------------------------------- ### ListInstallations Source: https://developer.safetyculture.com/reference/partnerintegrationservice_listinstallations Retrieves a paginated list of app installations. Use the `next_page_token` from the metadata to fetch subsequent pages. ```APIDOC ## GET /integrations/app/v1/installations ### Description Retrieves a list of app installations. ### Method GET ### Endpoint /integrations/app/v1/installations ### Parameters #### Query Parameters - **page_token** (string) - Optional - The token for the next page of results. ### Response #### Success Response (200) - **metadata** (s12.common.v1.PaginationMetadata) - The metadata for the response, including pagination information. - **apps** (array) - The list of app installations. - **app_id** (string) - The ID of the app. - **app_name** (string) - The name of the application. - **installation_id** (string) - The ID of this installation. - **installation_configuration** (string) - The configuration of the installation. #### Response Example ```json { "metadata": { "next_page": "/integrations/app/v1/installations?page_token=next_page_token_value", "next_page_token": "next_page_token_value" }, "apps": [ { "app_id": "app_123", "app_name": "Example App", "installation_id": "install_abc", "installation_configuration": "{\"setting\": \"value\"}" } ] } ``` ``` -------------------------------- ### Get Rapid Refresh by ID - Ruby Example Source: https://developer.safetyculture.com/reference/trainingrapidrefreshservice_getrapidrefreshbyid This Ruby script shows how to make a GET request to retrieve a specific rapid refresh training. It utilizes the 'net/http' library and requires you to provide your API token and the rapid refresh ID. ```ruby require 'net/http' require 'uri' api_url = URI.parse('https://api.safetyculture.com/training/rapid-refreshes/RAPID_REFRESH_ID') api_token = 'YOUR_API_TOKEN' http = Net::HTTP.new(api_url.host, api_url.port) http.use_ssl = true request = Net::HTTP::Get.new(api_url.request_uri) request['Authorization'] = "Bearer #{api_token}" response = http.request(request) if response.code == '200' puts response.body else puts "Error: #{response.code} - #{response.message}" end ``` -------------------------------- ### Protobuf Any type packing and unpacking examples Source: https://developer.safetyculture.com/reference/documentspublicservice_createfile Examples demonstrate how to pack and unpack arbitrary serialized protocol buffer messages using the `Any` type in C++, Java, Python, and Go. These utilities are useful for handling polymorphic data structures. ```protobuf Foo foo = ...; Any any; any.PackFrom(foo); ... if (any.UnpackTo(&foo)) { ... } ``` ```protobuf Foo foo = ...; Any any = Any.pack(foo); ... if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } ``` ```protobuf foo = Foo(...) any = Any() any.Pack(foo) ... if any.Is(Foo.DESCRIPTOR): any.Unpack(foo) ... ``` ```protobuf foo := &pb.Foo{...} any, err := ptypes.MarshalAny(foo) ... foo := &pb.Foo{} if err := ptypes.UnmarshalAny(any, foo); err != nil { ... } ``` -------------------------------- ### Get Activity Log Events Source: https://developer.safetyculture.com/reference-link/thepubservice_feedactivitylogevents Fetches a list of activity log events. You can control the number of results and the starting point using query parameters. ```APIDOC ## GET /feed/activity_log_events ### Description Retrieves a paginated feed of activity log events. ### Method GET ### Endpoint https://api.safetyculture.io/feed/activity_log_events ### Query Parameters - **limit** (int32) - Optional - Maximum number of entries to return. Capped at 250. - **offset** (int32) - Optional - Offset used for pagination. - **triggered_after** (date-time) - Optional - Time from when organisation activities were triggered. Accepts ISO date format (e.g., 2020-08-31T22:40:47.512Z). - **next_page_token** (string) - Optional - The page cursor for subsequent requests. ### Responses #### Success Response (200) - A successful response containing a list of activity log events. #### Error Response (default) - An unexpected error response. ``` -------------------------------- ### Occurrence Object Example Source: https://developer.safetyculture.com/reference/schedules-legacy Present on read responses only, this object indicates the start and due times of a schedule occurrence. It is null if the schedule is finished or has no future occurrences. ```json { "start": "2021-08-09T21:00:00Z", "due": "2021-08-10T05:00:00Z" } ``` -------------------------------- ### Get Rapid Refresh by ID - Node.js Example Source: https://developer.safetyculture.com/reference/trainingrapidrefreshservice_getrapidrefreshbyid This Node.js snippet demonstrates how to fetch a rapid refresh training by its ID using the SafetyCulture API. It includes setting up the request with the necessary headers and handling the response. ```javascript const fetch = require('node-fetch'); const apiUrl = 'https://api.safetyculture.com/training/rapid-refreshes/RAPID_REFRESH_ID'; const apiToken = 'YOUR_API_TOKEN'; fetch(apiUrl, { method: 'GET', headers: { 'Authorization': `Bearer ${apiToken}` } }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('Error fetching rapid refresh:', error); }); ``` -------------------------------- ### Get Rapid Refresh by ID - JavaScript Example Source: https://developer.safetyculture.com/reference/trainingrapidrefreshservice_getrapidrefreshbyid This JavaScript snippet shows how to retrieve a rapid refresh training using the Fetch API. It demonstrates setting the Authorization header with your API token and handling the JSON response. ```javascript async function getRapidRefreshById(rapidRefreshId, apiToken) { const apiUrl = `https://api.safetyculture.com/training/rapid-refreshes/${rapidRefreshId}`; try { const response = await fetch(apiUrl, { method: 'GET', headers: { 'Authorization': `Bearer ${apiToken}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); return data; } catch (error) { console.error('Error fetching rapid refresh:', error); } } // Example usage: // const myApiToken = 'YOUR_API_TOKEN'; // const myRapidRefreshId = 'RAPID_REFRESH_ID'; // getRapidRefreshById(myRapidRefreshId, myApiToken); ``` -------------------------------- ### Protobuf Any Type Example (Go) Source: https://developer.safetyculture.com/reference/webhooksservice_createwebhook Illustrates how to marshal and unmarshal a Protocol Buffer message into an 'Any' type in Go. This facilitates the transmission of diverse message types. ```go foo := &pb.Foo{...} any, err := ptypes.MarshalAny(foo) ... foo := &pb.Foo{} if err := ptypes.UnmarshalAny(any, foo); err != nil { ... ``` -------------------------------- ### Any Type Serialization and Deserialization Examples Source: https://developer.safetyculture.com/reference/oshaservice_listestablishments Demonstrates how to pack and unpack arbitrary serialized protocol buffer messages using the 'Any' type in C++, Java, Python, and Go. It also explains the JSON representation of 'Any' values. ```protobuf message Foo {} // Example 1: Pack and unpack a message in C++. // Foo foo = ...; // Any any; // any.PackFrom(foo); // ... // if (any.UnpackTo(&foo)) { // ... // } // Example 2: Pack and unpack a message in Java. // Foo foo = ...; // Any any = Any.pack(foo); // ... // if (any.is(Foo.class)) { // foo = any.unpack(Foo.class); // } // Example 3: Pack and unpack a message in Python. // foo = Foo(...) // any = Any() // any.Pack(foo) // ... // if any.Is(Foo.DESCRIPTOR): // any.Unpack(foo) // ... // Example 4: Pack and unpack a message in Go // foo := &pb.Foo{...} // any, err := ptypes.MarshalAny(foo) // ... // foo := &pb.Foo{} // if err := ptypes.UnmarshalAny(any, foo); err != nil { // ... // } // The pack methods provided by protobuf library will by default use // 'type.googleapis.com/full.type.name' as the type URL and the unpack // methods only use the fully qualified type name after the last '/' // in the type URL, for example "foo.bar.com/x/y.z" will yield type // name "y.z". // JSON // ==== The JSON representation of an `Any` value uses the regular representation of the deserialized, embedded message, with an additional field `@type` which contains the type URL. Example: // package google.profile; // message Person { // string first_name = 1; // string last_name = 2; // } // { // "@type": "type.googleapis.com/google.profile.Person", // "firstName": , // "lastName": // } // If the embedded message type is well-known and has a custom JSON // representation, that representation will be embedded adding a field // `value` which holds the custom JSON in addition to the `@type` // field. Example (for message [google.protobuf.Duration][]): // { // "@type": "type.googleapis.com/google.protobuf.Duration", // "value": "1.212s" // } ``` -------------------------------- ### Get Rapid Refresh by ID - cURL Example Source: https://developer.safetyculture.com/reference/trainingrapidrefreshservice_getrapidrefreshbyid Use this cURL command to retrieve a specific rapid refresh training by its ID. Ensure you replace 'YOUR_API_TOKEN' and 'RAPID_REFRESH_ID' with your actual token and the ID of the rapid refresh you want to fetch. ```curl curl -X GET https://api.safetyculture.com/training/rapid-refreshes/RAPID_REFRESH_ID \ -H "Authorization: Bearer YOUR_API_TOKEN" ``` -------------------------------- ### Protobuf Any Message Packing/Unpacking Examples Source: https://developer.safetyculture.com/reference/documenttypesservice_listdocumenttypes Examples demonstrate how to pack and unpack protobuf Any messages in C++, Java, Python, and Go. The pack methods use 'type.googleapis.com/full.type.name' as the type URL by default. ```protobuf message Foo {} // Example 1: Pack and unpack a message in C++. // Foo foo = ...; // Any any; // any.PackFrom(foo); // ... // if (any.UnpackTo(&foo)) { // ... // } ``` ```protobuf // Example 2: Pack and unpack a message in Java. // Foo foo = ...; // Any any = Any.pack(foo); // ... // if (any.is(Foo.class)) { // foo = any.unpack(Foo.class); // } ``` ```protobuf // Example 3: Pack and unpack a message in Python. // foo = Foo(...) // any = Any() // any.Pack(foo) // ... // if any.Is(Foo.DESCRIPTOR): // any.Unpack(foo) // ... ``` ```protobuf // Example 4: Pack and unpack a message in Go // foo := &pb.Foo{...} // any, err := ptypes.MarshalAny(foo) // ... // foo := &pb.Foo{} // if err := ptypes.UnmarshalAny(any, foo); err != nil { // ... // } ```