//native
type Square = {
token: string;
};
/**
* CreateMobileAuthorizationCode
* 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).
*/
export async function main(auth: Square, body: { location_id?: string }) {
const url = new URL(`https://connect.squareup.com/mobile/authorization-code`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago