### Get Organisations List (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to initialize the SDK, obtain an access token, and then use the organizations client to get a collection of organizations. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/organisations" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) orgClient := organisations.NewOrganisations(apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := orgClient.GetCollection(params, headers) } ``` -------------------------------- ### Get Batch Details using Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs This example shows how to authenticate and retrieve batch details using the Pingen Go SDK. It involves initializing the SDK, obtaining an access token, and then using the batches client. Ensure you have the SDK installed and replace placeholders with your actual credentials and IDs. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/batches" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) batchClient := batches.NewBatches("organisationID", apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := batchClient.GetDetails("batchId", params, headers) } ``` -------------------------------- ### Initialize SDK and Get Token (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to initialize the Pingen SDK, obtain an access token using client credentials, and prepare to make API requests. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letterevents" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letterevents.NewLetterEvents("organisationID", apiRequestor) resp, err := letterEvents.GetSentCollection(nil, nil) } ``` -------------------------------- ### Get Webhook Details - Go SDK Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to retrieve webhook details. It involves initializing the SDK, obtaining an access token, and then using the webhook client. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/webhooks" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) webhookClient := webhooks.NewWebhooks("organisationID", apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := webhookClient.GetDetails("webhookId", params, headers) } ``` -------------------------------- ### Authenticate and Get User Details with Pingen PHP SDK Source: https://api.pingen.com/documentation/swagger-docs This example demonstrates authenticating using OAuth 2.0 client credentials and then fetching user details via the Pingen PHP SDK. Ensure you have the SDK installed and configured with your client ID and secret. ```php_sdk 'YOUR_OAUTH2_CLIENT_ID', 'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET' ) ); $accessToken = $provider->getAccessToken('client_credentials'); $userEndpoint = (new \Pingen\Endpoints\UserEndpoint($accessToken)); $user = $userEndpoint->getDetails(); ``` -------------------------------- ### Get Organisation Details with Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs This example shows how to fetch organization details using the Pingen Go SDK. It includes initializing the SDK, obtaining an access token, and calling the GetDetails method. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/organisations" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) orgClient := organisations.NewOrganisations(apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := orgClient.GetDetails("organisationId", params, headers) } ``` -------------------------------- ### Send Batch using Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to send a batch. It initializes the SDK, obtains an access token, and then uses the batch client to send the batch with specified parameters. Ensure you have the SDK installed and replace placeholder credentials and IDs. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/batches" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) batchClient := batches.NewBatches("organisationID", apiRequestor) resp, err := batchClient.SendBatch("batchId", "fast", "simplex", "color") } ``` -------------------------------- ### Get User Associations (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This example shows how to retrieve user associations using the Pingen Go SDK. It includes initializing the SDK, obtaining an access token, and calling the GetCollection method. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/userassociations" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) userAssociationsClient := userassociations.NewUserAssociations(apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := userAssociationsClient.GetCollection(params, headers) } ``` -------------------------------- ### Get Authenticated User Details (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This example shows how to retrieve user details using the Pingen Go SDK. It includes initializing the SDK, obtaining an access token, and calling the user details endpoint. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/users" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) userClient := users.NewUsers(apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := userClient.GetDetails(params, headers) } ``` -------------------------------- ### Get Letter File using Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs This example shows how to use the Pingen Go SDK to authenticate and retrieve a letter file. It abstracts the direct HTTP requests and redirect handling. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letters" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letters.NewLetters("organisationID", apiRequestor) stream, err := letterClient.GetFile("letterId") } ``` -------------------------------- ### Initialize Pingen SDK and Get Issue Collection using Go SDK Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to initialize the Pingen SDK, obtain an access token, and then retrieve issue collection events. It requires client ID, client secret, and organization ID. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letterevents" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letterevents.NewLetterEvents("organisationID", apiRequestor) resp, err := letterEvents.GetIssueCollection(nil, nil) } ``` -------------------------------- ### Get Batch Collection using Pingen PHP SDK Source: https://api.pingen.com/documentation/swagger-docs This example demonstrates how to fetch a collection of batches using the Pingen PHP SDK. It requires setting up the SDK with your OAuth2 credentials and organization ID. ```php_sdk 'YOUR_OAUTH2_CLIENT_ID', 'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET' ) ); $accessToken = $provider->getAccessToken('client_credentials'); $batchesEndpoint = (new \Pingen\Endpoints\BatchesEndpoint($accessToken)) ->setOrganisationId('YOUR_ORGANISATION_UUID'); $batchCollection = $batchesEndpoint->getCollection(); foreach ($batchCollection->data as $entry) { dump($entry->attributes->file_original_name); } ``` -------------------------------- ### Create Batch with Pingen Python SDK Source: https://api.pingen.com/documentation/swagger-docs This example demonstrates creating a batch using the Pingen Python SDK. It handles OAuth token retrieval and batch creation, including error handling for API responses. Ensure you have the SDK installed and replace placeholder values. ```py_sdk import pingen2sdk pingen2sdk.client_id = "YOUR_OAUTH2_CLIENT_ID" pingen2sdk.client_secret = "YOUR_OAUTH2_CLIENT_SECRET" resp = pingen2sdk.OAuth.get_token( grant_type="client_credentials", scope="letter batch webhook organisation_read", ) Batches = pingen2sdk.Batches("YOUR_ORGANISATION_UUID", resp["access_token"]) try: response = Batches.upload_and_create_batch( "./letter.pdf", "test batch", "information", "letter.pdf", "left", "merge", "page", 1, "last_page", ) print(response.data) except pingen2sdk.error.PingenError as e: print(e.status_code) print(e.json_body) ``` -------------------------------- ### Get Undeliverable Letter Events (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to initialize the SDK, obtain an access token, and then fetch undeliverable letter events. It requires client credentials and specific scopes. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letterevents" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letterevents.NewLetterEvents("organisationID", apiRequestor) resp, err := letterEvents.GetUndeliverableCollection(nil, nil) } ``` -------------------------------- ### Using Pingen SDK for Batch Events in PHP Source: https://api.pingen.com/documentation/swagger-docs This example demonstrates how to use the Pingen PHP SDK to authenticate, retrieve a batch events collection, and iterate through the data. Ensure you have the SDK installed and configured. ```php_sdk 'YOUR_OAUTH2_CLIENT_ID', 'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET' ) ); $accessToken = $provider->getAccessToken('client_credentials'); $batchEventsEndpoint = (new \Pingen\Endpoints\BatchEventsEndpoint($accessToken)) ->setOrganisationId('YOUR_ORGANISATION_UUID') ->setLetterId('YOUR_BATCH_UUID'); $batchEventsCollection = $batchEventsEndpoint->getCollection(); foreach ($batchEventsCollection->data as $entry) { var_dump($entry->attributes->code); } ``` -------------------------------- ### Fetch Letter Details using Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs Utilize the Pingen Go SDK to authenticate and retrieve letter details. This example demonstrates initializing the SDK, obtaining an access token, and then using the letters client to get details. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letters" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letters.NewLetters("organisationID", apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := letterClient.GetDetails("letterId", params, headers) } ``` -------------------------------- ### User 2FA Setup GET Source: https://api.pingen.com/documentation/swagger-docs Retrieves the 2FA setup details for a user. ```APIDOC ## GET /users/2fa/setup ### Description Retrieves the 2FA setup details for a user, including the secret and image for QR code generation. ### Method GET ### Endpoint /users/2fa/setup ### Response #### Success Response (200) - **data** (object) - Contains user 2FA data. - **id** (string) - The user ID. - **type** (string) - The resource type, expected to be 'users'. - **attributes** (object) - The 2FA attributes. - **secret** (string) - The 2FA secret key. - **image** (string) - The base64 encoded image for the QR code. - **links** (object) - Links related to the user. - **related** (string) - URL to related resources. ``` -------------------------------- ### Go SDK Example for Uploading and Creating a Batch Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example demonstrates how to authenticate, obtain an access token, and then use the Pingen SDK to upload a file and create a batch. ```APIDOC ## Go SDK - Upload and Create Batch ### Description This example shows how to use the Pingen Go SDK to upload a file and create a batch. It covers authentication, obtaining an access token, and then utilizing the `batches` client to perform the upload and creation. ### Method SDK Method Call ### Endpoint N/A (SDK abstraction) ### Parameters - `clientId` (string) - Your Pingen API client ID. - `clientSecret` (string) - Your Pingen API client secret. - `environment` (string) - The Pingen API environment (e.g., "staging"). - `grant_type` (string) - OAuth grant type, typically "client_credentials". - `scope` (string) - Requested API scopes. - `organisationID` (string) - The UUID of the organization. - `filePath` (string) - The path to the file to be uploaded. - `batchName` (string) - The desired name for the batch. - `icon` (string) - The icon to associate with the batch (e.g., `batches.IconRocket`). - `fileName` (string) - The original name of the file being uploaded. - `addressPosition` (string) - The position of the address block (e.g., `batches.AddressPositionLeft`). - `groupingType` (string) - The type of grouping for the batch (e.g., `batches.GroupingTypeZip`). - `splitType` (string) - The type of splitting for the batch (e.g., `batches.SplitTypeFile`). - `splitSize` (integer, optional) - The size for splitting the batch. - `separator` (string, optional) - The separator character for splitting. - `splitPos` (string, optional) - The position for splitting. ### Request Example ```go config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) batchClient := batches.NewBatches("organisationID", apiRequestor) splitSize := 5 splitPos := batches.SplitPositionFirstPage separator := "comma" resp, err := batchClient.UploadAndCreateBatch( "test.zip", "Test Upload Batch", batches.IconRocket, "test.zip", batches.AddressPositionLeft, batches.GroupingTypeZip, batches.SplitTypeFile, &splitSize, &separator, &splitPos, ) ``` ### Response - `resp` (interface{}) - The response from the batch creation operation. - `err` (error) - An error object if the operation failed. ``` -------------------------------- ### Create Webhook with Pingen Go SDK Source: https://api.pingen.com/documentation/swagger-docs This example shows how to create a webhook using the Pingen Go SDK. It involves initializing the SDK, obtaining an access token, and then using the webhook client to create the webhook with the specified parameters. ```go_sdk import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/webhooks" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) webhookClient := webhooks.NewWebhooks("organisationID", apiRequestor) resp, err := webhookClient.Create("issues", "https://valid-url", "d09a095a0d1d2ae896f985c0fff1ad51") } ``` -------------------------------- ### Get User 2FA Setup by ID Source: https://api.pingen.com/documentation/swagger-docs Retrieves specific user 2FA setup information by its ID. ```APIDOC ## GET /websites/api_pingen/user_2fa_setup/{user2FASetupId} ### Description Retrieves specific user 2FA setup information using its unique identifier. ### Method GET ### Endpoint /websites/api_pingen/user_2fa_setup/{user2FASetupId} ### Parameters #### Path Parameters - **user2FASetupId** (string) - Required - The ID of the user 2FA setup information to retrieve. ``` -------------------------------- ### Get Webhook Collection (PHP SDK) Source: https://api.pingen.com/documentation/swagger-docs This PHP SDK example shows how to get a collection of webhooks. ```APIDOC ## Get Webhook Collection ### Description Retrieves a collection of webhooks using the Pingen PHP SDK. ### Method GET ### Endpoint (Endpoint is abstracted by the SDK) ### Parameters (Parameters are handled by the SDK methods.) ### Request Example ```php $provider = new \Pingen\Provider\Pingen( array( 'clientId' => 'YOUR_OAUTH2_CLIENT_ID', 'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET' ) ); $accessToken = $provider->getAccessToken('client_credentials'); $webhooksEndpoint = (new \Pingen\Endpoints\WebhooksEndpoint($accessToken)) ->setOrganisationId('YOUR_ORGANISATION_UUID'); $webhookCollection = $webhooksEndpoint->getCollection(); foreach ($webhookCollection->data as $entry) { dump($entry->attributes->event_category); } ``` ### Response #### Success Response - **data** (array) - Contains webhook objects. #### Response Example (Example shows iterating through the 'data' array and accessing 'event_category'.) ``` -------------------------------- ### Get User 2FA Setup Source: https://api.pingen.com/documentation/swagger-docs Retrieves user 2FA setup information, with options to specify fields and sorting. ```APIDOC ## GET /websites/api_pingen/user_2fa_setup ### Description Retrieves user 2FA setup information. You can specify which attributes of the users type to include in the output and define the sorting order. ### Method GET ### Endpoint /websites/api_pingen/user_2fa_setup ### Parameters #### Query Parameters - **fields[users]** (string) - Optional - Which attributes of users type should be specified in an output - **sort** (string) - Optional - Sorting expression. Defaults to "created_at". ``` -------------------------------- ### Initialize SDK and Get Webhooks (Go) Source: https://api.pingen.com/documentation/swagger-docs Initializes the Pingen SDK, obtains an access token, and retrieves a collection of webhooks for a specific organization. Ensure you have the correct client ID, client secret, and environment set. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/oauth" "github.com/pingencom/pingen2-sdk-go/webhooks" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) webhookClient := webhooks.NewWebhooks("organisationID", apiRequestor) params := map[string]string{} headers := map[string]string{} resp, err := webhookClient.GetCollection(params, headers) } ``` -------------------------------- ### Get User 2FA Setup Source: https://api.pingen.com/documentation/swagger-docs Retrieves the current Two-Factor Authentication setup for a user, including the secret key and image for QR code generation. ```APIDOC ## GET /users/{userId}/2fa-setup ### Description Retrieves the current Two-Factor Authentication setup for a user. ### Method GET ### Endpoint /users/{userId}/2fa-setup ### Parameters #### Path Parameters - **userId** (string) - Required - The unique identifier of the user. ### Response #### Success Response (200) - **data** (array) - An array containing the 2FA setup details for the user. - **id** (string) - The unique identifier of the 2FA setup entry. - **type** (string) - The type of resource, typically 'users'. - **attributes** (object) - Contains the 2FA secret and image. - **secret** (string) - The secret key for setting up 2FA. - **image** (string) - A base64 encoded string representing the QR code image. - **links** (object) - Links related to the 2FA setup. - **self** (string) - The URL for the self-link of the 2FA setup. - **links** (object) - Links related to the list of 2FA setups. - **self** (string) - The URL for the self-link of the list. - **meta** (object) - Metadata about the list. ### Response Example ```json { "data": [ { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "type": "users", "attributes": { "secret": "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF", "image": "base64encodedstring" }, "links": { "self": "/users/some-user-id/2fa-setup/some-setup-id" } } ], "links": { "self": "/users/some-user-id/2fa-setup" }, "meta": {} } ``` ``` -------------------------------- ### Calculate Letter Price with Go SDK Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example shows how to initialize the Pingen SDK, obtain an access token, and then use the `Letters` client to calculate the price of a letter. ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/letters" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) letterClient := letters.NewLetters("organisationID", apiRequestor) resp, err := letterClient.CalculatePrice("CH", []string{"normal", "qr"}, "simplex", "color", "fast") } ``` -------------------------------- ### Get User Associations (Python requests) Source: https://api.pingen.com/documentation/swagger-docs A Python example using the 'requests' library to get user associations. Remember to replace 'INSERT_YOUR_ACCESS_TOKEN_HERE' with your actual access token. ```py import requests url = 'https://api.pingen.com/user/associations' access_token = 'INSERT_YOUR_ACCESS_TOKEN_HERE' requests.get( url, headers = { 'Authorization': 'Bearer {}'.format(access_token) }) ``` -------------------------------- ### Upload and Create Letter (Go SDK) Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example demonstrates how to upload a file and create a letter using the Pingen API. It covers initializing the SDK, obtaining an access token, and using the `letterClient.UploadAndCreate` method. ```APIDOC ## Upload and Create Letter (Go SDK) ### Description This Go SDK example demonstrates how to upload a file and create a letter using the Pingen API. It covers initializing the SDK, obtaining an access token, and using the `letterClient.UploadAndCreate` method. ### Method `letterClient.UploadAndCreate` ### Parameters - `filePath` (string) - The path to the file to be uploaded. - `uploadedFileName` (string) - The desired name for the uploaded file. - `letterType` (string) - The type of letter (e.g., "left"). - `send` (bool) - Whether to send the letter immediately. - `deliveryClass` (string) - The delivery class (e.g., "fast"). - `printType` (string) - The print type (e.g., "simplex"). - `colorMode` (string) - The color mode (e.g., "color"). - `senderAddress` (string) - The sender's address. - `metadata` (map[string]interface{}) - Additional metadata for the letter, including recipient and sender details. ### Request Example ```go metaData := map[string]interface{}{ "recipient": map[string]string{ "name": "R_Example", "street": "R_Street", "number": "R_12", "zip": "R_12", "city": "R_Warsaw", "country": "PL", }, "sender": map[string]string{ "name": "S_Example", "street": "S_Street", "number": "S_12", "zip": "S_12", "city": "S_Warsaw", "country": "PL", }, } resp, err := letterClient.UploadAndCreate( "testFile.pdf", "uploaded-test.pdf", "left", true, "fast", "simplex", "color", "Example Sender Address", metaData, ) ``` ### Response #### Success Response The response contains details of the created letter. #### Response Example (Response structure not detailed in source) ``` -------------------------------- ### Get File Upload URL (HTTP - Java) Source: https://api.pingen.com/documentation/swagger-docs This Java example demonstrates how to make a GET request to the Pingen API to retrieve a file upload URL using an access token. ```APIDOC ## Get File Upload URL (Java) ### Description This Java code snippet shows how to fetch a file upload URL from the Pingen API using a GET request. It includes setting the authorization header with a bearer token and handling the response. ### Method GET ### Endpoint `https://api.pingen.com/file-upload` ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Request Example ```java String urlString = "https://api.pingen.com/file-upload"; String accessToken = "INSERT_YOUR_ACCESS_TOKEN_HERE"; URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", "Bearer " + accessToken); ``` ### Response #### Success Response (200 OK) - **(JSON Object)** - Contains the file upload URL and related information. ### Response Example ```json { "data": { "type": "file_upload", "id": "some-id", "attributes": { "url": "https://s3.amazonaws.com/your-bucket/your-object-key?AWSAccessKeyId=...", "method": "PUT" } } } ``` ``` -------------------------------- ### Get File Upload URL (HTTP - PHP) Source: https://api.pingen.com/documentation/swagger-docs This PHP example demonstrates how to make a GET request to the Pingen API to retrieve a file upload URL using cURL and an access token. ```APIDOC ## Get File Upload URL (PHP) ### Description This PHP code snippet uses cURL to make a GET request to the Pingen API to obtain a file upload URL. It shows how to set the authorization header and retrieve the response. ### Method GET ### Endpoint `https://api.pingen.com/file-upload` ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Request Example ```php $accessToken = 'INSERT_YOUR_ACCESS_TOKEN_HERE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.pingen.com/file-upload"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $headers = [ "Authorization: Bearer $accessToken" ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); echo $response; ``` ### Response #### Success Response (200 OK) - **(JSON Object)** - Contains the file upload URL and related information. ### Response Example ```json { "data": { "type": "file_upload", "id": "some-id", "attributes": { "url": "https://s3.amazonaws.com/your-bucket/your-object-key?AWSAccessKeyId=...", "method": "PUT" } } } ``` ``` -------------------------------- ### Get Organisation Letters (Java) Source: https://api.pingen.com/documentation/swagger-docs This Java example shows how to make an HTTP GET request to fetch letters for an organization. It handles setting the authorization header and processing the response status code. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] args) { String url = "https://api.pingen.com/organisations/INSERT_YOUR_ORGANISATION_UUID_HERE/letters"; String accessToken = "INSERT_YOUR_ACCESS_TOKEN_HERE"; try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", "Bearer " + accessToken); int statusCode = connection.getResponseCode(); if (statusCode == HttpURLConnection.HTTP_OK) { try (BufferedReader reader = new BufferedReader( new InputStreamReader(connection.getInputStream()))) { String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } System.out.println("Response: " + response.toString()); } } else { System.out.printf("Request failed. HTTP Status Code: %d%n", statusCode); } } catch (Exception e) { System.err.println("An error occurred: " + e.getMessage()); } } } ``` -------------------------------- ### Request File Upload URL (SDK - Go) Source: https://api.pingen.com/documentation/swagger-docs This Go SDK example demonstrates how to initialize the SDK, obtain an access token, and then use the FileUpload client to request a file upload URL. ```APIDOC ## Request File Upload URL (Go SDK) ### Description This example shows how to use the Pingen Go SDK to get a file upload URL. It covers SDK initialization, obtaining an OAuth token, and then making the request for the file upload URL. ### Usage ```go import ( "github.com/pingencom/pingen2-sdk-go" "github.com/pingencom/pingen2-sdk-go/api" "github.com/pingencom/pingen2-sdk-go/fileupload" "github.com/pingencom/pingen2-sdk-go/oauth" ) func main() { config, _ := pingen2sdk.InitSDK( "clientId", "clientSecret", "staging", ) params := map[string]string{ "grant_type": "client_credentials", "scope": "letter batch webhook organisation_read user", } tokenResp, err := oauth.GetToken(config, params) accessToken := tokenResp["access_token"].(string) apiRequestor := api.NewAPIRequestor(accessToken, config) fileUploadClient := fileupload.NewFileUpload(requestor) response, err := fileUploader.RequestFileUpload() } ``` ``` -------------------------------- ### Java Example for Creating a Batch Source: https://api.pingen.com/documentation/swagger-docs This Java example demonstrates how to create a batch using the Pingen API. It involves obtaining a file upload URL, uploading the file, and then submitting the batch creation request. ```APIDOC ## Java - Create Batch ### Description This Java code demonstrates the process of creating a batch using the Pingen API. It outlines the steps for obtaining a file upload URL, uploading the actual file, and then making a POST request to create the batch with the file details. ### Method HTTP POST and GET requests. ### Endpoint - File Upload URL: `https://api.pingen.com/file-upload` (GET) - Batch Creation URL: `https://api.pingen.com/organisations/YOUR_ORGANISATION_UUID/batches` (POST) ### Parameters #### Path Parameters - `YOUR_ORGANISATION_UUID` (string) - The unique identifier for your organization. #### Query Parameters None explicitly shown for batch creation. #### Request Body (for Batch Creation POST request) ```json { "data": { "type": "batches", "attributes": { "name": "Batch Name", "icon": "campaign", "file_original_name": "your_filename.pdf", "file_url": "", "file_url_signature": "", "address_position": "left", "grouping_type": "merge", "grouping_options_split_type": "page", "grouping_options_split_size": 2 } } } ``` #### Request Body (for File Upload GET request - implicit) This step involves getting a pre-signed URL and signature for uploading the file. ### Request Example ```java // Step 1: Get file upload URL and signature JSONObject fileUploadResponse = sendGetRequest(urlFileUpload, accessToken); JSONObject fileUploadData = fileUploadResponse.getJSONObject("data").getJSONObject("attributes"); String fileUrl = fileUploadData.getString("url"); String fileUrlSignature = fileUploadData.getString("url_signature"); // Step 2: Upload the file to the file URL String filePath = "path_to_your_file.pdf"; // Replace with your file path uploadFile(fileUrl, filePath); // Step 3: Create a batch JSONObject payload = new JSONObject() .put("data", new JSONObject() .put("type", "batches") .put("attributes", new JSONObject() .put("name", "Batch Name") .put("icon", "campaign") .put("file_original_name", "your_filename.pdf") .put("file_url", fileUrl) .put("file_url_signature", fileUrlSignature) .put("address_position", "left") .put("grouping_type", "merge") .put("grouping_options_split_type", "page") .put("grouping_options_split_size", 2) ) ); sendPostRequest(urlBatches, payload, accessToken); ``` ### Response #### Success Response (200) - **data** (JSONObject) - Contains details about the created batch. - **attributes** (JSONObject) - Attributes of the batch. - `id` (string) - The unique identifier for the batch. - `name` (string) - The name of the batch. - `created_at` (string) - Timestamp of batch creation. - `status` (string) - Current status of the batch. #### Response Example (File Upload) ```json { "data": { "type": "file_upload", "attributes": { "url": "https://example.com/upload-url", "url_signature": "example_signature", "expires_at": "2023-10-27T10:00:00Z" } } } ``` #### Response Example (Batch Creation) ```json { "data": { "type": "batches", "id": "batch_uuid_123", "attributes": { "name": "Batch Name", "icon": "campaign", "file_original_name": "your_filename.pdf", "file_url": "https://example.com/uploaded-file.pdf", "file_url_signature": "example_signature", "address_position": "left", "grouping_type": "merge", "grouping_options_split_type": "page", "grouping_options_split_size": 2, "created_at": "2023-10-26T10:00:00Z", "status": "pending" } } } ``` ``` -------------------------------- ### Get File Upload URL (HTTP - Python) Source: https://api.pingen.com/documentation/swagger-docs This Python example demonstrates how to make a GET request to the Pingen API to retrieve a file upload URL using the requests library and an access token. ```APIDOC ## Get File Upload URL (Python) ### Description This Python code snippet uses the `requests` library to perform a GET request to the Pingen API for a file upload URL. It shows how to include the authorization header. ### Method GET ### Endpoint `https://api.pingen.com/file-upload` ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Request Example ```python import requests url = 'https://api.pingen.com/file-upload' access_token = 'INSERT_YOUR_ACCESS_TOKEN_HERE' requests.get(url, headers = { 'Authorization': 'Bearer {}'.format(access_token) }) ``` ### Response #### Success Response (200 OK) - **(JSON Object)** - Contains the file upload URL and related information. ### Response Example ```json { "data": { "type": "file_upload", "id": "some-id", "attributes": { "url": "https://s3.amazonaws.com/your-bucket/your-object-key?AWSAccessKeyId=...", "method": "PUT" } } } ``` ``` -------------------------------- ### Get Letter Events Collection (PHP SDK) Source: https://api.pingen.com/documentation/swagger-docs This PHP SDK example shows how to retrieve a collection of letter events. ```APIDOC ## Get Letter Events Collection (PHP SDK) ### Description Fetches a collection of letter events using the Pingen PHP SDK. ### Method `getCollection()` ### Parameters None directly on the method, configuration is done via the `LetterEventsEndpoint` object. ### Request Example ```php require __DIR__ . '/vendor/autoload.php'; $provider = new \Pingen\Provider\Pingen( array( 'clientId' => 'YOUR_OAUTH2_CLIENT_ID', 'clientSecret' => 'YOUR_OAUTH2_CLIENT_SECRET' ) ); $accessToken = $provider->getAccessToken('client_credentials'); $letterEventsEndpoint = (new \Pingen\Endpoints\LetterEventsEndpoint($accessToken)) ->setOrganisationId('YOUR_ORGANISATION_UUID') ->setLetterId('YOUR_LETTER_UUID'); $letterEventsCollection = $letterEventsEndpoint->getCollection(); foreach ($letterEventsCollection->data as $entry) { var_dump($entry->attributes->code); } ``` ### Response - `$letterEventsCollection` - An object containing the collection of letter events. ```