Skip to main content
Answered

Attempt to fetch conversation ratings returning undefined

  • 13 June 2024
  • 2 replies
  • 53 views

I’m also interested in fetching other report metrics (Median response time, New Conversations) from my account to my app and I’m confused about the API Reporting Docs. I’m attempting to use the Node SDK. I’m not sure if I’m structuring the query correctly or using the proper conversations methods, but I’m getting an undefined in my console. The env variables are properly being read, I’ve tested them in my console. In the code below, I’m trying to get conversation rating from the past 7 days

import { Client, Operators } from "intercom-client";

import * as dotenv from "dotenv";

dotenv.config();

const client = new Client({

tokenAuth: { token: `${process.env.ACCESS_TOKEN}` },

});

client.useRequestOpts({

baseURL: ‘https://api.eu.intercom.ioconversations’,

});

// Get today's date

const today = new Date();

// Calculate the date 7 days ago

const sevenDaysAgo = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);

// Convert the date to a Unix timestamp (in seconds)

const sevenDaysAgoTimestamp = Math.floor(sevenDaysAgo.getTime() / 1000);

 

async function run() {

try {

const response = await client.conversations.search({

data: {

query: {

field: "conversation_rating.replied_at",

operator: Operators.GREATER_THAN,

value: sevenDaysAgoTimestamp,

},

pagination: {

per_page: 5,

},

},

});

console.log(response);

return response;

} catch (err) {

console.error(err);

}

}

 

run();

2 replies

Btw in baseURL, I am adding the slash https://api.eu.intercom.io/conversations

Userlevel 3
Badge +4

Hi @Dana Nhem ! Ebenezer here from Engineering Support👋.

Since you already speaking to me over in the inbox, we’ll continue from there.

See you on the flip side!

Reply