0

Receives batched logs from integration applications.

by
Published Dec 20, 2024

This endpoint receives batched logs from integration applications on partner platforms. Note: If you're interested in joining the beta, please reach out to your Pinterest account manager.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Receives batched logs from integration applications.
7
 * This endpoint receives batched logs from integration applications on partner platforms.
8
Note: If you're interested in joining the beta, please reach out to your Pinterest account manager.
9
 */
10
export async function main(
11
  auth: Pinterest,
12
  body: {
13
    logs: {
14
      client_timestamp: number;
15
      event_type: "APP" | "API";
16
      log_level: "INFO" | "WARN" | "ERROR";
17
      external_business_id?: string;
18
      advertiser_id?: string;
19
      merchant_id?: string;
20
      tag_id?: string;
21
      feed_profile_id?: string;
22
      message?: string;
23
      app_version_number?: string;
24
      platform_version_number?: string;
25
      error?: {
26
        cause?: string;
27
        column_number?: number;
28
        file_name?: string;
29
        line_number?: number;
30
        message?: string;
31
        message_detail?: string;
32
        name?: string;
33
        number?: number;
34
        stack_trace?: string;
35
      };
36
      request?: {
37
        method:
38
          | "GET"
39
          | "HEAD"
40
          | "POST"
41
          | "PUT"
42
          | "DELETE"
43
          | "CONNECT"
44
          | "OPTIONS"
45
          | "TRACE"
46
          | "PATCH";
47
        host: string;
48
        path: string;
49
        request_headers?: {};
50
        response_headers?: {};
51
        response_status_code?: number;
52
      };
53
    }[];
54
  },
55
) {
56
  const url = new URL(`https://api.pinterest.com/v5/integrations/logs`);
57

58
  const response = await fetch(url, {
59
    method: "POST",
60
    headers: {
61
      "Content-Type": "application/json",
62
      Authorization: "Bearer " + auth.token,
63
    },
64
    body: JSON.stringify(body),
65
  });
66
  if (!response.ok) {
67
    const text = await response.text();
68
    throw new Error(`${response.status} ${text}`);
69
  }
70
  return await response.json();
71
}
72