marketo_get_form_by_id
Retrieve a Marketo form by its ID to access full metadata, including fields, submit button label, and visibility rules.
Instructions
Get a single Marketo form by its ID. Returns full form metadata including fields, submit button label, and visibility rules.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Form ID |
Implementation Reference
- src/tools/forms.ts:33-38 (handler)The handler function for 'marketo_get_form_by_id'. Makes an authenticated GET request to Marketo's Asset API at /rest/asset/v1/form/{id}.json using the shared makeRequest helper.
async (args) => { try { return ok(await makeRequest(`/rest/asset/v1/form/${args.id}.json`)); } catch (e) { return err(e); } } ); - src/tools/forms.ts:30-32 (schema)Input schema for 'marketo_get_form_by_id': requires a single numeric 'id' parameter.
{ id: z.number().describe("Form ID"), }, - src/tools/forms.ts:27-38 (registration)Registration of the 'marketo_get_form_by_id' tool via server.tool(), including name, description, schema, and handler.
server.tool( "marketo_get_form_by_id", "Get a single Marketo form by its ID. Returns full form metadata including fields, submit button label, and visibility rules.", { id: z.number().describe("Form ID"), }, async (args) => { try { return ok(await makeRequest(`/rest/asset/v1/form/${args.id}.json`)); } catch (e) { return err(e); } } ); - src/client.ts:21-49 (helper)The makeRequest helper used by the handler to perform authenticated HTTP requests to the Marketo API.
export async function makeRequest<T = unknown>( endpoint: string, method: Method = "GET", data?: unknown, contentType?: string, ): Promise<T> { const token = await getAccessToken(); const config: AxiosRequestConfig = { url: `${MARKETO_BASE_URL}${endpoint}`, method, headers: { Authorization: `Bearer ${token}`, ...(contentType ? { "Content-Type": contentType } : {}), }, ...(data && method !== "GET" ? { data } : {}), ...(data && method === "GET" ? { params: data } : {}), }; const res = await axios(config); const body = res.data; // Marketo REST API returns errors inside the response body if (body?.errors?.length) { const e = body.errors[0]; throw new MarketoError(`${e.code}: ${e.message}`, res.status); } return body as T; } - src/client.ts:53-65 (helper)The 'ok' and 'err' response helpers used by the handler to format successful/error responses.
export function ok(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } export function err(e: unknown) { const msg = e instanceof Error ? e.message : String(e); return { isError: true, content: [{ type: "text" as const, text: `Error: ${msg}` }], }; }