---
title: "Examples of the Web AR API SDK"
slug: "examples-of-the-web-ar-api-sdk"
description: "Learn how to check for WebAR assets, implement AR features, and optimize your product pages for enhanced user experience and faster loading times."
updated: 2025-05-22T03:03:45Z
published: 2025-05-22T03:03:45Z
canonical: "developers.3dcloud.com/examples-of-the-web-ar-api-sdk"
---
> ## Documentation Index
> Fetch the complete documentation index at: https://developers.3dcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.
# Examples of the Web AR API SDK
**ALL EXAMPLES ASSUME USAGE FROM CDN. IF USING FROM NPM, REMOVE** `MxtWebAR.` **PREFIX FROM ALL CLASS CALLS**
Note also, that all examples are functions… don't forget to actually call these functions! Also, feel free to have these outside of functions, in your functions, or whatever you want to do!
## Checking if an SKU has a WebAR asset
It is usually a good idea to use this call before using `getWebArPregeneratedUrl` as it is faster, and the manifest is used to determine if the webAR asset exists in browser cached for one hour.
So, for example, if you are using WebAR assets on your PDP pages, as customers go between different PDP pages, the manifest will get browser cached and calls to `getAssetTypesAvailable` should be lightning fast.
In the example below, make sure that you replace myApiKey and myClientId with your own, as provided by your Account Director.
```javascript
async function checkForWebArAsset(sku) {
const browserArType = MxtWebAR.MxtWebArHelpers.browserArSupport();
const pregenerated = new MxtWebAR.MxtWebArPregenerated({apiKey:'myApiKey', clientId:'myClientId'});
try {
const arAssetsAvailable = await pregenerated.getAssetTypesAvailable(sku);
if(!browserArType) {
//CANT USE WEB AR IN THIS BROWSER, if there are arAssetsAvailable, make a QR code to direct the user to the redirect page.
}
else if(arAssetsAvailable.includes(browserArType)) {
//Web AR Assets are available and work in this browser!
}
else {
//Web AR Assets would work in this browser, but we don't have any!
}
} catch(e) {
console.error('Failed to check if sku has web ar asset', e);
}
}
```
## Adding the WebAR Asset to an element="" as="" the="">>
After checking that the SKU has a WebAR asset, you can get the WebAR asset by doing this.
- NOTE: you can use the same `pregenerated` instance that was created in the previous example; you do not have to create a new one.
- NOTE: this will automatically format the URL in a way the browser understands, in order to open it as a WebAR asset.
In the example below, make sure that you replace myApiKey and myClientId with your own, as provided by your Account Director.
```javascript
async function addHrefToAnchorTag(anchorElement, sku) {
try {
const pregenerated = new MxtWebAR.MxtWebArPregenerated({apiKey:'myApiKey', clientId:'myClientId'});
const url = await pregenerated.getWebArPregeneratedUrl(sku);
anchorElement.href = url;
} catch(e) {
console.error('Failed to get sku web ar asset', e);
return false;
}
}
```
### For iOS - THIS IS VERY IMPORTANT - PLEASE READ
iOS has some bizarreness in recognizing URLs on href tags as WebAR assets, *especially* inside in-app browsers. 3D Cloud found that using this code will remedy that bizarre behavior:
```javascript
Launch AR
```
- `rel="ar"` is how iOS determines that this is an AR asset.
- `<>` tag is required inside of the `<>` tag as the first direct child of the element.
- NOTE: this can be left empty or it can include whatever image you would like that indicates that this will open WebAR view. Example: `img src="https://marxentresearch.com/demo/web-ar/img/Icon-ARIcon.svg"`
- `launch>launch>` can go inside the `<>` tag, the text can say “View in Room” or “See in AR”, whatever you’d like.
- NOTE: this is an example of an optional feature that you may want to leverage.
- NOTE: only one span tag can be included directly under the `<>` tag. Additional spans can be nested.
**If you want to deploy directly to your website or a test page, you can simply import this code in a >**
NOTE: is easily obtained by using the `getWebArPregeneratedUrl` method. Documented here: [Details of the WebAR Asset API SDK | MxtWebArPregenerated](/3d-cloud-webar/docs/details-of-the-webar-asset-api-sdk#mxtwebarpregenerated)
```javascript
```
## Getting the GLB Model of an Asset
This is the code to get the GLB file (using this option has no formatting for opening as a WebAR asset in the browser).
```javascript
async function getGlbModel(sku) {
try {
const pregenerated = new MxtWebAR.MxtWebArPregenerated({apiKey:'myApiKey', clientId:'myClientId'});
const url = await pregenerated.getGlb(sku);
return url;
} catch(e) {
console.error('Failed to get sku web ar asset', e);
return false;
}
}
```
## Getting an Asset from a Particular Environment
By default, the SDK defaults to the PRODUCTION (live) environment. To get something from the TEST or STAGING environment, provide an additional option to the constructor like so:
```javascript
const pregenerated = new MxtWebAR.MxtWebArPregenerated({apiKey:'myApiKey', clientId:'myClientId', serviceEnvironment:MxtWebAR.MxtAssetEnvironment.STAGING});
```
## Getting an Asset of a Particular State
By default, the SDK defaults to the PRODUCTION (live) state of an asset. To get the TEST or STAGING state, provide an additional option to the constructor like so:
```javascript
const pregenerated = new MxtWebAR.MxtWebArPregenerated({apiKey:'myApiKey', clientId:'myClientId', assetEnvironment:MxtWebAR.MxtAssetEnvironment.STAGING});
```
## Getting an Asset of a Particular LOD (level of detail)
Assets default to 512x512 pixel textures if no LOD is provided. To provide a specific LOD, use:
```javascript
const url = await pregenerated.getWebArPregeneratedUrl(sku, LOD._1024);
```
OR
```javascript
const url = await pregenerated.getGlb(sku, LOD._1024);
```
---
## Launching a Product from a QR Code
Although spins of a GLB asset are possible on desktop, launching into AR is only supported on Mobile.
It is a common path therefore on desktop, to show a “View in AR” capability, but have it show a QR code to scan on a mobile device.
**Creating a QR Code**
Here is an example of this using the QRious library, though any QR Code library will do.
```xml