Edits history of script submission #11208 for ' Create a request to access an existing partner's assets. (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create a request to access an existing partner's assets.
     * Create a request to access an existing partner's assets with the specified permissions. The request will be sent to the partner for approval. The assets that can be requested are ad accounts and profiles.
     */
    export async function main(
      auth: Pinterest,
      business_id: string,
      body: {
        asset_requests: { partner_id: string; asset_id_to_permissions: {} }[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/businesses/${business_id}/requests/assets/access`,
      );
    
      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 536 days ago