Skip to main content

1. Prerequisites

To follow this guide, you will need to:

2. Install and initialize the CodeQR TypeScript SDK

1

Install

Install the CodeQR TypeScript SDK using your preferred package manager:
2

Initialize

Then, initialize the CodeQR TypeScript SDK with your API key.
lib/codeqr.ts
You can now use the codeqr object to interact with the CodeQR API.
Let’s create a short link using the CodeQR TypeScript SDK.
create-link.ts
Optionally, you can also pass an externalId field which is a unique identifier for the link in your own database to associate it with the link in CodeQR’s system.
create-link-external-id.ts
This will let you easily update the link or retrieve analytics for it later on using the externalId instead of the CodeQR linkId. CodeQR TypeScript SDK provides a method to upsert a link – where an existing link is updated if it exists, or a new link is created if it doesn’t. so you don’t have to worry about checking if the link already exists.
upsert-link.ts
This way, you won’t have to worry about checking if the link already exists when you’re creating it. Let’s update an existing link using the CodeQR TypeScript SDK. You can do that in two ways:
  • Using the link’s linkId in CodeQR’s system.
  • Using the link’s externalId in your own database (prefixed with ext_).
update-link.ts
CodeQR allows you to retrieve analytics for a link using the CodeQR TypeScript SDK.
get-analytics.ts
Similarly, you can retrieve analytics for a link using the externalId field.
get-analytics-external-id.ts

7. Examples

TypeScript Example

See the full example on GitHub.