Skip to content

Commit bcbbe7e

Browse files
authored
Added get started and OAuth startup flow (iZettle#145)
* Draft for getting started with a dev account and OAuth
1 parent 130f5b0 commit bcbbe7e

18 files changed

+374
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Sign up for a Zettle developer account
2+
===
3+
Before you start to build an app with Zettle, you need to sign up for a Zettle developer account.
4+
5+
* [Prerequisites](#prerequisites)
6+
* [Sign up for a Zettle developer account](#sign-up-for-a-zettle-developer-account)
7+
* [Next task](#next-task)
8+
* [Related API reference](#related-api-reference)
9+
10+
## Prerequisites
11+
* None
12+
13+
## Sign up for a Zettle developer account
14+
15+
1. Create an account at [Zettle Developer Portal](https://developer.zettle.com/register).
16+
2. Go to your email and find an email from Zettle that asks you to verify your email address.
17+
3. Follow the instruction in the email to verify your email address.
18+
19+
After that, you will receive a welcome email from Zettle with the Developer Platform Agreement. Now you're ready to start building with Zettle.
20+
21+
## Next task
22+
* To build a self-hosted app that is hosted by merchants individually, [create a self-hosted app](../../oauth-api/user-guides/create-an-app/create-a-self-hosted-app).
23+
* To build a partner-hosted app that is hosted by you as an integrator, [create a partner-hosted app](../../oauth-api/user-guides/create-an-app/create-a-partner-hosted-app.md).
24+
25+
## Related API reference
26+
* None
Loading
21.9 KB
Loading
Loading
Loading

oauth-api/images/copy-key.png

47.2 KB
Loading
18.2 KB
Loading
Loading
Loading
Loading
Loading
28.9 KB
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Create a partner-hosted app
2+
===
3+
A partner-hosted app is hosted by you as an integrator. To authorise, the app uses the authorisation code grant.
4+
5+
In an authorisation code grant flow, you use a temporary authorisation code to exchange for an access token from the authorisation server. A temporary authorisation code is generated from the authorisation server using API credentials. API credentials include a client secret and client ID.
6+
7+
To authorise your app using authorisation code grant, you need to get API credentials for the app by creating an app in your Dashboard on the [Developer Portal](https://developer.zettle.com/).
8+
> **Note:** If you want to build a self-hosted app that will be hosted by merchants, [create a self-hosted app](create-a-self-hosted-app).
9+
10+
* [Prerequisites](#prerequisites)
11+
* [Get API credentials for a new app](#get-api-credentials-for-a-new-app)
12+
* [Request a new client secret for an existing app](#request-a-new-client-secret-for-an-existing-app)
13+
* [Next task](#next-task)
14+
* [Related API reference](#related-api-reference)
15+
16+
## Prerequisites
17+
* You have an account for the [Developer Portal](https://developer.zettle.com/). If you don't have an account, [sign up for a developer account](../../../get-started/user-guides/sign-up-for-a-developer-account.md).
18+
19+
## Get API credentials for a new app
20+
If you need API credentials for a new app, create a public app in your Dashboard.
21+
22+
1. Log in to the [Developer Portal](https://developer.zettle.com/).
23+
2. On your Dashboard, click **Create a new app**. <!-- screesshot. Click or select?-->
24+
25+
<img id="create-a-new-app-from-your-dashboard" src="../../images/create-a-new-app-from-your-dashboard.png" alt="This screenshot shows the Create a new app button on the right of your Dashboard." >
26+
3. On the Create a new app page, click **Public API credentials** to open the form for the new app.
27+
4. Fill in the form for the new app.
28+
29+
<img id="fill-in-the-form-for-the-new-app-partner-hosted" src="../../images/fill-in-the-form-for-the-new-app-partner-hosted.png" alt="This screenshot shows a form where you fill in the app name, app URL, and the company name. Optionally, you can add OAuth Redirect URIs that redirect merchants to your app after successful login to Zettle." >
30+
5. Click **Get credentials** to create your API credentials.
31+
6. Download your API credentials and save them somewhere safe.
32+
33+
<img id="download-your-API-credentials" src="../../images/download-your-API-credentials.png" alt="This screenshot shows your API credentials and the Download credentials button." >
34+
35+
> **Tip:** As the client ID doesn't change, if you lose the API credentials, you can [request a new client secret](#request-a-new-client-secret-for-an-existing-app).
36+
37+
## Request a new client secret for an existing app
38+
The client ID of an existing app doesn't change. If you need a new client secret for an existing app, request it in your Dashboard.
39+
40+
1. Log in to the [Developer Portal](https://developer.zettle.com/).
41+
2. On your Dashboard, choose the app for which you need to request a new secret. The current client secret is hidden.
42+
43+
<img id="choose-the-app-that-needs-a-new-client-secret" src="../../images/choose-the-app-that-needs-a-new-client-secret.png" alt="This screenshot shows where you can choose the app that needs a new client secret on your Dashboard." >
44+
45+
3. On the app page, click **Request new client secret** to deactivate the current secret and generate a new secret. The new client secret will be shown.
46+
47+
<img id="request-a-new-client-secret" src="../../images/request-a-new-client-secret.png" alt="This screenshot shows the Request new client secret button on the right of your Dashboard." >
48+
49+
4. Download your API credentials and save them somewhere safe.
50+
51+
## Next task
52+
* [Set up authorisation code grant](../set-up-app-authorisation/set-up-authorisation-code-grant.md)
53+
54+
## Related API reference
55+
* [OAuth2 API Reference](../../../authorization.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Create a self-hosted app
2+
===
3+
A self-hosted app is hosted by one or more merchants individually. To authorise, the app uses the authorisation assertion grant.
4+
5+
In an authorisation assertion grant flow, you use a JSON web token (JWT) assertion to request an access token from the authorisation server. The JWT assertion is used as an API key. An API key is created by a merchant (Zettle merchant account owner). It's valid until the merchant revokes it.
6+
<!-- add assertion grant in glossary -->
7+
8+
To authorise your app using assertion grant, you need to ask the merchant (Zettle merchant account owner) to create an API key at my.zettle.com. You can provide the merchant a deep link that directs them to the API creation page or steps to create an API key.
9+
10+
> **Note:** If you want to build a partner-hosted app that will be hosted by you as an integrator, [create a partner-hosted app](../create-a-partner-hosted-app.md).
11+
12+
* [Prerequisites](#prerequisites)
13+
* [Step 1: Get an API key from a Zettle merchant](#step-1-get-an-api-key-from-a-zettle-merchant)
14+
* [Step 2 (Optional): Prepare for app tracking](#step-2-optional-prepare-for-app-tracking)
15+
* [Next task](#next-task)
16+
* [Related API reference](#related-api-reference)
17+
18+
## Prerequisites
19+
* You have an account for the [Developer Portal](https://developer.zettle.com/). If you don't have an account, [sign up for a developer account](../../../../get-started/user-guides/sign-up-for-a-developer-account.md).
20+
21+
## Step 1: Get an API key from a Zettle merchant
22+
An API key must be created by the Zettle merchant that will use your app.
23+
24+
1. Ask the merchant to create an API key in one of the following ways:
25+
* Provide the merchant a deep link with pre-populated fields and [the instructions to create an API key with the deep link](create-an-api-key.md#create-an-api-key-with-a-deep-link-from-the-developer).
26+
```
27+
https://my.zettle.com/apps/api-keys?name=<key-name>&scopes=<scopes>
28+
```
29+
Where:
30+
* `<key-name>` should be the name under which the API key is stored. Keep it short and descriptive. One good practice is to use the integration name as the key name, for example, `WooCommerce`.
31+
* `<scopes>` should contain the list of needed OAuth scopes separated by a space, for example, `READ:PURCHASE%20READ:FINANCE`.
32+
33+
Example:
34+
```
35+
https://my.zettle.com/apps/api-keys?name=WooCommerce&scopes=READ:PURCHASE%20READ:FINANCE
36+
```
37+
* Provide the merchant OAuth scopes and [the instructions to create an API key with the OAuth scopes](create-an-api-key.md#create-an-api-key-with-oauth-scopes-from-the-developer).
38+
39+
2. Ask the merchant to share the created API key and client ID with you.
40+
41+
## Step 2 (Optional): Prepare for app tracking
42+
App tracking is optional. To track a self-hosted app, you need to use the following when setting up the authorisation assertion grant flow for the app:
43+
44+
* The API key from the merchant
45+
* The client ID of a partner-hosted app
46+
47+
> **Note:** The client ID that you receive from the merchant cannot be used to track a self-hosted app. If you want to track a self-hosted app, you need to use the client ID of a partner-hosted app instead of the client ID from the merchant.
48+
49+
To prepare for tracking a self-hosted app:
50+
1. [Create a partner-hosting app](../create-a-partner-hosted-app.md).
51+
2. When setting up the authorisation assertion grant flow, make sure to use the client ID of the partner-hosted app instead of the client ID from the merchant.
52+
53+
## Next task
54+
* [Set up authorisation assertion grant](../../set-up-app-authorisation/set-up-authorisation-assertion-grant.md)
55+
56+
## Related API reference
57+
* [OAuth2 API Reference](../../../../authorization.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Create an API key
2+
======
3+
4+
An API key is used in the authorisation assertion grant flow for an app. It must be created by a Zettle merchant in their my.zettle.com.
5+
6+
If you're developer of a self-hosted app, share this guide with the merchant that will use the app.
7+
8+
* [Create an API key with a link from the developer](#create-an-api-key-with-a-link-from-the-developer)
9+
* [Create an API with OAuth scopes from the developer](#create-an-api-key-with-oauth-scopes-from-the-developer)
10+
11+
## Prerequisites
12+
* You are a Zettle merchant and have an account at my.zettle.com.
13+
* You have a link or OAuth scopes from the developer of the app that you will use. The OAuth scopes are permissions that you give to the developer to access your Zettle account data.
14+
15+
## Create an API key with a link from the developer
16+
17+
1. Open the link from the developer.
18+
19+
2. Enter your Zettle account password.
20+
21+
3. Review the information and click **Create key**. A client ID will be created together with the API key.
22+
23+
<img id="create-API-keys-from-the-deep-link" src="../../../images/create-API-keys-from-the-deep-link.png" alt="This screenshot shows the dialog that is started after clicking a deep link for creating API keys. You can find the Create key button in the lower right corner of the dialog.">
24+
25+
4. On the Create API key page, click **Copy key**. Keep the API key and the client ID as secret somewhere safe.
26+
27+
<img id="copy-key" src="../../../images/copy-key.png" alt="This screenshot shows the dialog where you can copy the API key and save it for later use. You can find the Copy key button in the lower right corner of the dialog.">
28+
29+
5. Share the API key and client ID with the developer who sent you the link.
30+
31+
The created key is shown in the list of keys. After the integration starts working with the key, the Last used column will show the last time the integration accessed your Zettle data.
32+
33+
<img id="available-API-keys" src="../../../images/available-API-keys.png" alt="This screenshot shows the dialog where you can see a list of created API keys and their scopes.">
34+
35+
## Create an API key with OAuth scopes from the developer
36+
37+
1. Go to [my.zettle.com](https://my.zettle.com/) and log in to your account.
38+
39+
2. On the left panel, click **Integrations**.
40+
41+
<img id="check-integrations-in-my.zettle.com" src="../../../images/check-integrations-in-my.zettle.com.png" alt="This screenshot shows my zettle.com where you can find the Integrations link in the lower left corner of the left navigation menu.">
42+
43+
3. Under the Integration tools section, click **API Keys**.
44+
45+
<img id="API-keys-in-Integration-tools" src="../../../images/API-keys-in-Integration-tools.png" alt="This screenshot shows the Integrations page where you can find the API keys link in the lower left corner of the left navigation menu on the page.">
46+
47+
4. Click **Create API Key**.
48+
49+
<img id="create-API-key-dialog" src="../../../images/create-API-key-dialog.png" alt="This screenshot shows the Available API keys page where you can find the Create API key button in the upper right corner before the available API keys list on the page.">
50+
51+
5. Give a name to your key. Keep it short and descriptive. One good practice is to use the integration name as the key name.
52+
53+
6. Select the OAuth scopes that the developer provided. The OAuth scopes are permissions that you give to the developer to access your Zettle account data.
54+
55+
7. Click **Create key**. A client ID will be created together with the API key.
56+
57+
<img id="select-scopes-create-API-keys-dialog" src="../../../images/select-scopes-create-API-keys-dialog.png" alt="This screenshot shows the dialog where you can select scopes for the API key that you will create. You can find the Create key button in the lower right corner of the dialog.">
58+
59+
8. Confirm your password.
60+
61+
9. On the Create API key page, click **Copy key**. Keep the API key and the client ID as secret somewhere safe.
62+
63+
<img id="copy-key" src="../../../images/copy-key.png" alt="This screenshot shows the dialog where you can copy the API key and save it for later use. You can find the Copy key button in the lower right corner of the dialog.">
64+
65+
10. Share the API key and client ID with the developer.
66+
67+
The created key is shown in the list of keys. After the integration starts working with the key, the Last used column will show the last time the integration accessed your Zettle data.
68+
69+
<img id="available-API-keys" src="../../../images/available-API-keys.png" alt="This screenshot shows the Available API keys page where you can see a list of created API keys.">
70+
71+
## Related task
72+
* [Create a self-hosted app](create-a-self-hosted-app.md)
73+
74+
## Related API reference
75+
None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Set up authorisation assertion grant
2+
===
3+
4+
To build a self-hosted app with APIs, you need to set up the authorisation assertion grant flow for the app using an API key. An API key is a JSON web token (JWT) assertion.
5+
6+
* [Prerequisites](#prerequisites)
7+
* [Step 1: Retrieve an access token from an API key](#step-1-retrieve-an-access-token-from-an-api-key)
8+
* [Step 2: Generate a new access token from the API key](#step-2-generate-a-new-access-token-from-the-api-key)
9+
* [Previous task](#previous-task)
10+
* [Related API reference](#related-api-reference)
11+
12+
## Prerequisites
13+
* You have an account for the [Developer Portal](https://developer.zettle.com/). If you don't have an account, [sign up for a developer account](../../../get-started/user-guides/sign-up-for-a-developer-account.md).
14+
15+
* You have an API key and a client ID for the app. If you don't have any, [create a self-hosted app](../create-an-app/create-a-self-hosted-app).
16+
17+
## Step 1: Retrieve an access token from an API key
18+
To retrieve a short-lived access token from the API key, include the API key and the client ID in the following request.
19+
> **Note:** If you plan to track the app later on, [use the client ID of a partner-hosting app instead of the client ID from the merchant](../create-an-app/create-a-self-hosted-app/create-a-self-hosted-app.md#step-2-optional-prepare-for-app-tracking).
20+
21+
```
22+
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&client_id={client_ID}&assertion={API_key}" https://oauth.zettle.com/token
23+
```
24+
25+
Example:
26+
27+
The following example retrieves an access token using the assertion grant flow. The response value `expires_in` is the remaining lifetime of the access token in seconds. The access token is valid for 7200 seconds.
28+
29+
Request
30+
```
31+
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&client_id=6adde977-c34d-4de1-99b2-f6ed3e65431a&assertion=eyJraWQiOiIwIiwidHlwIjoiSl...y9V15QKjn4ZgKRumYb_ikw" https://oauth.zettle.com/token
32+
```
33+
Response
34+
```json
35+
{
36+
"access_token": "eyJraWQiOiIxNDQ0NzI3MTY0Njk4Iiwi...yZA",
37+
"expires_in": 7200
38+
}
39+
```
40+
41+
> **Note:** If the API key is invalid or revoked by the merchant (Zettle account owner), the response returns error `invalid_grant`. You need to [get a new API key from the merchant](../create-an-app/create-a-self-hosted-app/create-a-self-hosted-app.md#step-1-get-an-api-key-from-a-zettle-merchant).
42+
43+
44+
## Step 2: Generate a new access token from the API key
45+
An access token is valid only for 7200 seconds. Use the same API key to generate a new access token, as in [Step 1: Retrieve an access token from an API key](#step-1-retrieve-an-access-token-from-an-api-key).
46+
47+
48+
## Previous task
49+
* [Create a self-hosted app](../create-an-app/create-a-self-hosted-app)
50+
51+
## Related API reference
52+
* [OAuth2 API Reference](../../../authorization.md)

0 commit comments

Comments
 (0)