//native
type Grist = {
apiKey: string;
host: string;
};
/**
* Add rows to a table
* Deprecated in favor of `records` endpoints. We have no immediate plans to remove these endpoints, but consider `records` a better starting point for new projects.
*/
export async function main(
auth: Grist,
docId: string,
tableId: string,
noparse: string | undefined,
body: {},
) {
const url = new URL(
`https://${auth.host}/api/docs/${docId}/tables/${tableId}/data`,
);
for (const [k, v] of [["noparse", noparse]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
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 329 days ago