Asset Layer Docs
Asset LayerAPI Docs
  • 👋Welcome
  • Getting Started
    • Quick Start
      • Quick Start for Developers
      • Quick Start for Creators
      • Quick Start for Unity
    • Core Concepts
      • Users
      • Auth + Permissions
      • Teams
      • Apps
      • Slots
      • Expressions
      • Assets + Collections
      • Currencies
      • Marketplace and Shops
      • Core Concepts in Action
    • SDK Docs
      • Setup
      • Users
        • getUser()
      • Apps
        • info()
        • getApp()
        • getApps()
        • slots()
        • getAppSlots()
        • getAppSlotIds()
      • Slots
        • getSlot()
        • collections()
        • getSlotCollections()
        • getSlotCollectionIds()
        • getSlotExpressions()
        • createExpression()
        • updateExpression()
        • getExpressionTypes()
      • Collections
        • info()
        • getCollection()
        • getCollections()
        • assets()
        • getCollectionAssets()
        • getCollectionAssetIds()
        • createCollection()
        • updateCollection()
        • updateCollectionImage()
        • activateCollection()
        • deactivateCollection()
      • Assets
        • info()
        • getAsset()
        • getAssets()
        • user()
        • getUserAssets()
        • getUserAssetIds()
        • getUserAssetCounts()
        • getUserCollectionAssets()
        • getUserCollectionsAssets()
        • getUserSlotAssets()
        • getUserSlotsAssets()
        • mintAssets()
        • send()
        • sendAsset()
        • sendAssets()
        • sendCollectionAssets()
        • sendLowestAsset()
        • sendRandomAsset()
        • update()
        • updateAsset()
        • updateAssets()
        • updateCollectionAssets()
        • expressionValues()
        • updateAssetExpressionValue()
        • updateAssetsExpressionValue()
        • updateCollectionAssetsExpressionValue()
        • updateBulkExpressionValues()
      • Equips
        • getEquips()
        • setEquip()
        • removeEquip()
      • Currencies
        • info()
        • getCurrency()
        • balance()
        • getCurrencyBalance()
        • getCurrencySummary()
        • increaseCurrencyBalance()
        • decreaseCurrencyBalance()
        • transferCurrency()
      • Listings
        • getListing()
        • user()
        • getUserListings()
        • getUserListingsCounts()
        • getUserCollectionListings()
        • getUserCollectionListingsCounts()
        • getUserSales()
        • getUserSalesCounts()
        • getUserPurchases()
        • getUserPurchasesCounts()
        • collection()
        • getCollectionListings()
        • getCollectionsListings()
        • getCollectionListingsCounts()
        • getCollectionsListingsCounts()
        • getCollectionListingsStats()
        • getCollectionsListingsStats()
        • app()
        • getAppListings()
        • getAppListingsCounts()
        • getAppListingsStats()
        • new()
        • listAsset()
        • listAssets()
        • listCollectionAssets()
        • updateListing()
        • buyListing()
        • removeListing()
      • Shop
        • buyItem()
        • summary()
      • Core Types
        • User
        • App
        • Slot
        • Expression
        • Collection
        • Asset
        • Equip
        • Currency
        • Listing
        • Shop
        • Basic
      • SDK Repo
      • C# SDK for Unity
    • Guides
      • How to Integrate Asset Layer into your Unity Game
    • API Docs
    • Asset Layer GPT
  • Build an app
    • App Setup
      • Creating an App
      • Managing Apps
      • App Info
      • Manage Permissions
      • Manage Slots
      • Manage Collections
      • Manage Currencies
      • App Settings
    • App Development
    • Build With Unity
      • Unity App Setup
      • Advanced Unity Setup
        • WebGL App Setup
      • Asset Layer Unity SDK
        • Login + Authentication
        • Create Assets in Unity
        • Import Assets Into Your Scene
        • Inventory Manager
        • Sync Your Assets
        • Asset Layer Game Server
        • C# SDK
    • Sample App
      • Getting Started With Sample App Locally
      • Environment Variables
      • API Routes
      • Deployment
      • Default Pages
      • Deploying Your Unity WebGL Game Through Sample App
  • Create and Manage Assets
    • Create Assets With Code
    • Create Assets Without Code
      • Create Assets for My App
      • Submit a Collection for a 3rd Party App
      • Create an Independent Collection - Coming Soon!
    • Create Assets in Unity
    • Managing Collections from 3rd Party Creators
  • Manage Assets
    • My Assets
      • Listing Assets for Sale
      • Sending Assets as a Gift
      • My Listings
      • Marketplace History
    • Marketplace
  • Settings
    • Team Settings
    • Account Settings
    • Pricing
  • Details
    • Expression Types
      • Image
      • Audio
      • Video
      • Unity
      • Spine 4.0 (2D Animated Characters)
      • Additional Expression Types
Powered by GitBook
On this page
  • Installation
  • Reference the SDK
  • Instantiate the SDK
  • Make a Request
  • Login a User
  • Logout a User
  • Handling an active session
  • Request Details
  1. Getting Started
  2. SDK Docs

Setup

PreviousSDK DocsNextUsers

Last updated 1 year ago

For an easy way to get started testing the SDK, use where you can enter your app secret, login, and then make requests in the browser console.

Installation

To install and set up the library, run:

$ npm install @assetlayer/sdk-client

Or if you prefer using Yarn:

$ yarn add @assetlayer/sdk-client

Just want to

Reference the SDK

You can reference the SDK in two ways:

import { AssetLayer } from '@assetlayer/sdk-client';

OR

const { AssetLayer } = require('@assetlayer/sdk-client');

Instantiate the SDK

You can instantiate the SDK with your app secret, or with a base URL. Only use your app secret server side in a production environment. Client requests should be sent to a proxy server. To set up a proxy server for your app, you can use our open source Express.js server or our Sample App as a starting point.

const assetlayer = new AssetLayer({appSecret: "YOUR APP SECRET"});

Or

const assetlayer = new AssetLayer({baseUrl: "YOUR SERVER URL"});

You can also instantiate the SDK via CDN in an HTML file.

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script src="https://unpkg.com/@assetlayer/sdk-client@latest/dist/index.umd.js"></script>
</head>
<body>
  <script>
    const assetlayer= new AssetLayer();
  </script>
</body>
</html>

Make a Request

As a first request, use your appId and call getApp.

const app = await assetlayer.apps.getApp({ appId: '633b30ca09d1acacd0c50df4' });

By default, handlers return the payload and will throw Errors. You can get the raw response by calling the raw handler as shown below:

const response = await assetlayer.apps.raw.getApp({ appId: '633b30ca09d1acacd0c50df4' });

The raw handlers can be useful in situations where more data from the response is required. However, it can still throw an error, to fix that we can call the safe handler as shown below:

const { result: app, error } = await assetlayer.apps.safe.getApp({ appId: '633b30ca09d1acacd0c50df4' });

Login a User

Logging in a user is as simple as:

assetlayer.loginUser();

This will trigger a prompt for the user to sign-in. You can skip the email prompt by providing an email like so:

assetlayer.loginUser({ email });

You can also directly pass in a did token (unregistered). With this method you can await the response:

const success = await assetlayer.loginUser({ didToken });

When not passing a didToken, you must rely on a callback. To handle a successful login you have to pass in an onSuccess handler:

assetlayer.loginUser({ onSuccess: async () => console.log(await assetlayer.users.getUser()) });

Note that you must use a web browser or similar environment for authentication.

Logout a User

assetlayer.logoutUser();

Handling an active session

Using initialize, you can sign in a user if there's already an active session:

const loggedIn = await assetlayer.initialize();

This will return whether or not the user was successfully logged in. You can also pass it an onComplete handler:

assetlayer.initialize((loggedIn) => { if (!loggedIn) assetlayer.loginUser(); });

Request Details

By default, handlers return the payload and will throw Errors. You can get the raw response by calling the raw handler as shown below:

const response = await assetlayer.apps.raw.getApp({ appId: '633b30ca09d1acacd0c50df4' });

The raw handlers can be useful in situations where more data from the response is required. However, it can still throw an error, to fix that we can call the safe handler as shown below:

const { result: app, error } = await assetlayer.apps.safe.getApp({ appId: '633b30ca09d1acacd0c50df4' });

Some endpoints may have different return types depending on the provided properties. For this reason, there are more specific handlers available:

const appOrApps:App|App[] = await assetlayer.apps.info({ appId: 'YOUR_APP_ID', appIds: ['APP_ID_1', 'APP_ID_2'] });
const app:App = await assetlayer.apps.getApp({ appId: 'YOUR_APP_ID' });
const apps:App[] = await assetlayer.apps.getApps({ appIds: ['APP_ID_1', 'APP_ID_2'] });

These all call the same core endpoint (), but getApp & getApps offer stricter type security when passing props and returning values. Typescript is highly recommended and the sdk includes extensive typings, useful for referencing & importing, allowing for turn-key type-safe app development.

our testing page
https://api-v2.assetlayer.com/api/v1/app/info