Has Anyone Successfully Integrated ChatPDF into a Workflow despite Invalid API Response Errors?

This topic was automatically generated from Slack. You can find the original thread here.

Has anyone had any luck integrating ChatPDF into a workflow? I keep getting the error the API response was invalid.

Hi Tyler - are you using a pre-built action or using Python/Node.js code to integrate?

I’m using Node.js to integrate

Got it, could you share the error message exactly? Just curious, because usually the error is that the request is invalid, not the response

Yeah. It’s actually in the logs, because the script was successful.

Here it is:

4, 12:57:16 PM
Extracted PDF URL: https://www.jotform.com/uploads/bluebotautomation/233556713962160/5836720704561105911/37993_Anderson_Maple_Syrup_Inc_Valuation (1).pdf


Copy
2/28/2024, 12:57:17 PM
API Response: undefined

2/28/2024, 12:57:17 PM
Source ID not found in response: undefined

Could you share the Node.js code as well? Would help us understand the context of the logs

You bet

import { axios } from "@pipedream/platform"

export default defineComponent({
  async run({ steps, $ }) {
    const pdfUrl = steps.trigger.event.newRow[145]; // Assuming this is the correct index for the PDF URL
    console.log('Extracted PDF URL:', pdfUrl);

    const options = {
      headers: {
        'x-api-key': process.env.CHATPDF_API_KEY,
        'Content-Type': 'application/json'
      },
      data: {
        url: pdfUrl
      }
    };

    try {
      const response = await axios($, {
        method: "POST",
        url: "https://api.chatpdf.com/v1/sources/add-url",
        headers: options.headers,
        data: options.data
      });
      console.log('API Response:', response.data);
      
      if (response.data && response.data.sourceId) {
        console.log('Source ID:', response.data.sourceId);
      } else {
        console.error('Source ID not found in response:', response.data);
      }
    } catch (error) {
      console.error('Error making API request:', error.response ? error.response.data : error.message);
    }
  },
})

Ah I see you’re using @pipedream/platform’s version of axios.

I don’t believe you’ll need to drill into the .data key of the response. It just returns the data by default.

const data = await axios($, {
// rest of request config here

That seems to have done it! Thanks Pierce

Sure thing :slightly_smiling_face:

Would it be helpful to you to have a ChatPDF app integrated on our platform Tyler? We can add it to our backlog if so!

Hey - absolutely!
I put together a script, but it’s a lot less accurate with its responses than the actual platform. If there was an app integrated I would only assume that would improve.
It also seems to circumnavigate the token limit I bump up against a lot with the traditional GPT interface.

I’ll add it to our app backlog and let you know once we have ChatPDF onboarded!

, the base integration to ChatPDF is complete - I’ll add some components for the team to build next!

Woot woot! Thanks !