Readme

(Part of: https://www.val.town/v/vtdocs.resyBot)

Get a user's auth token and payment methods.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { fetch } from "https://esm.town/v/std/fetch";
import { resyPublicAPIKey } from "https://esm.town/v/vtdocs/resyPublicAPIKey";
export const resyAuth = async (email: string, password: string): Promise<{
token: string;
paymentMethods: {
id: number;
type: string;
}[];
}> => {
const authRes = await fetch("https://api.resy.com/3/auth/password", {
"headers": {
"authorization": `ResyAPI api_key="${resyPublicAPIKey}"`,
"content-type": "application/x-www-form-urlencoded",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
},
"body": `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`,
"method": "POST",
});
const authJSON = await authRes.json();
if (!authJSON.token) {
throw new Error(`couldn't auth: ${authJSON}`);
}
return {
token: authJSON.token,
paymentMethods: authJSON.payment_methods,
};
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 6, 2024