0

CreateMobileAuthorizationCode

by
Published Oct 17, 2025

Generates code to authorize a mobile application to connect to a Square card reader. Authorization codes are one-time-use codes and expire 60 minutes after being issued. __Important:__ The `Authorization` header you provide to this endpoint must have the following format: ``` Authorization: Bearer ACCESS_TOKEN ``` Replace `ACCESS_TOKEN` with a [valid production authorization credential](https://developer.squareup.com/docs/build-basics/access-tokens).

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CreateMobileAuthorizationCode
7
 * Generates code to authorize a mobile application to connect to a Square card reader.
8

9
Authorization codes are one-time-use codes and expire 60 minutes after being issued.
10

11
__Important:__ The `Authorization` header you provide to this endpoint must have the following format:
12

13
```
14
Authorization: Bearer ACCESS_TOKEN
15
```
16

17
Replace `ACCESS_TOKEN` with a
18
[valid production authorization credential](https://developer.squareup.com/docs/build-basics/access-tokens).
19
 */
20
export async function main(auth: Square, body: { location_id?: string }) {
21
  const url = new URL(`https://connect.squareup.com/mobile/authorization-code`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37