Skip to main content
Answered

Attempt to fetch conversation ratings returning undefined


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();

Best answer by Ebenezer.Laleye

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!

View original
Did this topic help you find an answer to your question?

2 replies

  • Author
  • New Participant
  • 1 reply
  • June 13, 2024

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


Forum|alt.badge.img+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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings