API call to get tasks Error

I try to get tasks from API:

My code is in Google Apps Script, here is the error I got:

Error: {
 "success":false,
 "error":"Required suites missing",
 "errorCode":402,
 "error_info":"Please check developers.pipedrive.com"}

Please help me to figure out the reason.

My options are:

{
  "method": "get",
  "contentType": "application/json"
}

Endpoint is:

https://api.pipedrive.com/v1/tasks?api_token=MY_API_TOKEN_HERE

I'm sure token is correct as other API endpoints work fine.

Tagged:

Answers

  • inacyakup
    inacyakup Member Posts: 177
    5 Likes First Answer First Comment Name Dropper

    Hi Max,

    I can see that there is no problem with the endpoint with Postman. Could you share the code you used in the Apps script section?

  • Max Makhrov
    Max Makhrov Member Posts: 4
    Name Dropper First Comment Photogenic
    edited December 2023 #3

    Thanks for the quick response,

    Here is the code I use:

    /**
     * @returns {Array<Object>} tasks
     */
    function test_getPipeDriveTasks() {
      const apiEndpoint = "/v1/tasks";
      const result = getPipedrive_(apiEndpoint);
      console.log(result);
      return result.data;
    }
    
    
    ///////////////////////////// API calling function //////////////////////////
    
    /**
     * @typedef {Object} PipeDriveApiCommonParams
     * @prop {String} api_token
     * @prop {Number} limit
     * @prop {Number} start
     * @prop {String} [method]
     * @prop {Object} [payload]
     */
    
    
    /**
     * @param {String} apiEndpoint
     * @param {PipeDriveApiCommonParams} [params]
     * 
     * @returns {Object} data
     */
    function getPipedrive_(apiEndpoint, params = {}) {
      const basicUrl = `https://api.pipedrive.com${apiEndpoint}`;
      params.api_token = 'PUT_YOUR_API_TOKEN_HERE';
      const endpoint = getUrlParametrized_(params, basicUrl);
      const methhod = params.method || 'get';
      const options = {
        'method': methhod,
        'contentType': 'application/json',
        'muteHttpExceptions': true
      };
      if (params.payload) {
        options.payload = params.payload;
      }
      try {
        const response = UrlFetchApp.fetch(endpoint, options);
        const statusCode = response.getResponseCode();
        if (statusCode === 200) {
          var data = JSON.parse(response.getContentText());
          return data;
        } else {
          console.log(`Error: ${response.getContentText()}`);
        }
      } catch (e) {
        console.log('Exception caught while fetching Pipedrive deals: ' + e.toString());
      }
    }
    
    /**
     * @param {Object} obj
     * @param {String} url
     * 
     * @returns {String}
     */
    function getUrlParametrized_(obj, url) {
      let v, vals = [];
      for (let k in obj) {
        v = k + '=' + encodeURIComponent(obj[k]);
        vals.push(v);
      }
      const params = vals.join('&');
      return url + '?' + params;
    }
    


    In order to reproduce the error:

    1. Create a new script file, use script.new URL shortcut for that
    2. Copy my code
    3. Change token to yours: PUT_YOUR_API_TOKEN_HERE
    4. Run the function

    In my case I've got the error in logs:

    Error: {"success":false,"error":"Required suites missing","errorCode":402,"error_info":"Please check developers.pipedrive.com"}

    If you will not see the same error, this may be specific to my client's PipeDrive account,

  • inacyakup
    inacyakup Member Posts: 177
    5 Likes First Answer First Comment Name Dropper

    When I run the code, I get the output successfully. The output is as follows:

    {success:true,data:[{id:1,....

    You may need to talk to support for this.

  • Max Makhrov
    Max Makhrov Member Posts: 4
    Name Dropper First Comment Photogenic

    Thanks for testing. If I'll have a response from support, I'll post a solution here.

  • Max Makhrov
    Max Makhrov Member Posts: 4
    Name Dropper First Comment Photogenic

    The error text was not too helpful, but support helped a lot.

    The reason was dummy: my client's Projects subscription has ended.

    Special thanks to @inacyakup for very fast help here.


  • inacyakup
    inacyakup Member Posts: 177
    5 Likes First Answer First Comment Name Dropper

    Hi @Max Makhrov

    You're welcome, if I could help, it would make me happy :)


    Good Works