Business Value Calculator with API

Johannes_1205
Johannes_1205 Member Posts: 1 VERIFIED MEMBER
edited July 9 in Apps and Integrations #1

Hi there,

I want to program a business value calculator that creates a new lead in Pipedrive via API by entering the gathered information into the Lead Tab of Pipedrive.

Now there is a lot of miscellaneous information about how to achieve that. However, when I execute a test node.js file, it always tells me that OAuth 2 authentification failed. Do I really need to go through the whole process of setting up a Pipedrive App just to get a token? I dont have a callback URL or whatsoever I just want my code to send information to Pipedrive and create a Lead with it…

How else could I reach that?

Thanks in advance.

Answers

  • Leonardo Zimmermann
    Leonardo Zimmermann Pipedrive Team Posts: 153 PIPEDRIVE TEAM
    Third Anniversary 100 Comments 5 Answers 5 Likes

    Hey, @Johannes_1205!

    To create a new lead in Pipedrive using API without the complexity of OAuth 2.0, you can use an API token, which is a simpler and more straightforward approach. For that, however, a Pipedrive account needs to be created.

    For that, log in to your Pipedrive account and navigate to your account settings to find the "API" section. Copy your API token from there. Next, you need to install axios, a popular HTTP client for Node.js, if you haven't already. You can install it by running:

    bashCopy codenpm install axios
    

    Now, create a new Node.js file, say createLead.js, and add the following code:

    javascriptCopy codeconst axios = require('axios');
    
    const API_TOKEN = 'your_pipedrive_api_token_here';
    const PIPEDRIVE_API_URL = 'https://api.pipedrive.com/v1/leads';
    
    const createLead = async () => {
      const leadData = {
        title: 'New Business Lead',
        person_id: 1,  // Assuming you have a person_id to link the lead to
        organization_id: 1, // Assuming you have an organization_id to link the lead to
        // Add other lead details as required by your business logic
      };
    
      try {
        const response = await axios.post(PIPEDRIVE_API_URL, leadData, {
          headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${API_TOKEN}`
          }
        });
    
        if (response.data.success) {
          console.log('Lead created successfully:', response.data.data);
        } else {
          console.error('Error creating lead:', response.data.error);
        }
      } catch (error) {
        console.error('Error:', error.response ? error.response.data : error.message);
      }
    };
    
    createLead();
    
    

    Replace 'your_pipedrive_api_token_here' with your actual Pipedrive API token and customize the leadData object with the necessary fields for your leads. The code uses axios to send a POST request to the Pipedrive API to create a new lead, including the API token in the Authorization header.

    Finally, run your Node.js script using:

    bashCopy codenode createLead.js
    

    This should create a new lead in your Pipedrive account using the provided information. If you encounter any errors, the error details will be logged to the console, helping you diagnose and fix any issues.

    I hope this helps :)