Giter Club home page Giter Club logo

fingerprint-pro-server-api-go-sdk's Introduction

Fingerprint logo

CI badge CI badge CI badge Discord server

Fingerprint Pro Server Go SDK

Fingerprint is a device intelligence platform offering 99.5% accurate visitor identification. Fingerprint Pro Server API allows you to get information about visitors and about individual events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device.

This Go package is automatically generated by the Swagger Codegen project:

  • API version: 3
  • Package version: 5.0.2
  • Build package: io.swagger.codegen.v3.generators.go.GoClientCodegen

Requirements

Go Lang 1.20 or higher

We keep the Go support policy and support the last two major versions of Go.

Installation & Usage

  1. Get the package from GitHub:
go get github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v5/sdk
  1. Import and use the library:
package main

import (
	"context"
	"fmt"
	"github.com/antihax/optional"
	"github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v5/sdk"
	"log"
)

func main() {
	cfg := sdk.NewConfiguration()
	client := sdk.NewAPIClient(cfg)

	// You can also use sdk.RegionUS or sdk.RegionAsia. Default one is sdk.RegionUS
	//cfg.ChangeRegion(sdk.RegionEU)

	// Configure authorization, in our case with API Key
	auth := context.WithValue(context.Background(), sdk.ContextAPIKey, sdk.APIKey{
		Key: "SECRET_API_KEY",
	})
	// Usually this data will come from your frontend app
	visitorId := "VISITOR_ID"
	opts := sdk.FingerprintApiGetVisitsOpts{
		RequestId: optional.NewString("REQUEST_ID"),
	}
	response, httpRes, err := client.FingerprintApi.GetVisits(auth, visitorId, &opts)
	fmt.Printf("%+v\n", httpRes)
	if err != nil {
		switch err.(type) {
		case *sdk.GenericSwaggerError:
			switch model := err.(sdk.GenericSwaggerError).Model().(type) {
			case sdk.ManyRequestsResponse:
				log.Printf("Too many requests, retry after %d seconds", model.RetryAfter)
			}

		default:
			log.Fatal(err)
		}

	}
	fmt.Printf("Got response with visitorId: %s", response.VisitorId)
}

Note You can also check examples located in example directory. To run the examples:

cd example && FINGERPRINT_API_KEY=SECRET_API_KEY VISITOR_ID=VISITOR_ID_EXAMPLE go run getVisits.go

Alternatively, you can define your environment variables inside example/.env file and run the examples without passing them as arguments. If your subscription region is not the “Global/US” region, use REGION=eu or REGION=ap in the line above or in your local .env file.

Region

If your subscription is in region other than US, you need to change the region in the configuration:

import (
    "github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v5/sdk"
)

func main() {
    cfg := sdk.NewConfiguration()

    cfg.ChangeRegion(sdk.RegionEU) // or sdk.RegionAsia
}

Sealed results

This SDK provides utility methods for decoding sealed results. Install the sealed results dependency as below:

go get github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v5/sdk/sealed

Then you can use below code to unseal results:

package main

import (
	"encoding/base64"
	"fmt"
	"github.com/fingerprintjs/fingerprint-pro-server-api-go-sdk/v5/sdk/sealed"
	"os"
)

// Utility function to decode base64 string
func base64Decode(input string) []byte {
	output, err := base64.StdEncoding.DecodeString(input)
	if err != nil {
		panic(err)
	}
	return output
}

func main() {
	// Sealed result from the frontend.
	sealedResult := base64Decode(os.Getenv("BASE64_SEALED_RESULT"))
	// Base64 encoded key generated in the dashboard.
	key := base64Decode(os.Getenv("BASE64_SEALED_RESULT_KEY"))

	keys := []sealed.DecryptionKey{
		// You can provide more than one key to support key rotation. The SDK will try to decrypt the result with each key.
		{
			Key:       key,
			Algorithm: sealed.AlgorithmAES256GCM,
		},
	}
	unsealedResponse, err := sealed.UnsealEventsResponse(sealedResult, keys)

	if err != nil {
		panic(err)
	}

	// Do something with unsealed response, e.g: send it back to the frontend.
	fmt.Println(unsealedResponse)
}

To learn more, refer to example located in example/sealedResults.go.

Documentation for API Endpoints

All URIs are relative to https://api.fpjs.io

Class Method HTTP request Description
FingerprintApi GetEvent Get /events/{request_id} Get event by requestId
FingerprintApi GetVisits Get /visitors/{visitor_id} Get visits by visitorId

Documentation For Models

Documentation For Authorization

ApiKeyHeader

  • Type: API key
  • API key parameter name: Auth-API-Key
  • Location: HTTP header

ApiKeyQuery

  • Type: API key
  • API key parameter name: api_key
  • Location: URL query string

Documentation for sealed results

Author

[email protected]

Support and feedback

To report problems, ask questions or provide feedback, please use Issues. If you need private support, you can email us at [email protected].

License

This project is licensed under the MIT license.

fingerprint-pro-server-api-go-sdk's People

Contributors

dependabot[bot] avatar ilfa avatar jurouhlar avatar makma avatar necipallef avatar orkuncakilkaya avatar semantic-release-bot avatar theunderscorer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fingerprint-pro-server-api-go-sdk's Issues

Doc for ChangeRegion func

I realized that we have a function for changing a region, after experiencing HTTP 403 responses. The README should mention the usage of this function and the importance of using it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.