//native
type Square = {
token: string;
};
/**
* CreateDeviceCode
* Creates a DeviceCode that can be used to login to a Square Terminal device to enter the connected
terminal mode.
*/
export async function main(
auth: Square,
body: {
idempotency_key: string;
device_code: {
id?: string;
name?: string;
code?: string;
device_id?: string;
product_type: "TERMINAL_API";
location_id?: string;
status?: "UNKNOWN" | "UNPAIRED" | "PAIRED" | "EXPIRED";
pair_by?: string;
created_at?: string;
status_changed_at?: string;
paired_at?: string;
};
},
) {
const url = new URL(`https://connect.squareup.com/v2/devices/codes`);
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