【问题标题】:GatsbyJS : Where to put the script to call the Hubspot APIGatsbyJS : 将调用 Hubspot API 的脚本放在哪里
【发布时间】:2020-03-10 13:19:50
【问题描述】:

我需要将用户信息从 Hubspot 提取到我在 AWS Amplify 上托管的 Gatsby 站点。在他们的文档中,在 NodeJS 下,他们提供了这段示例代码:

var request = require("request");

var options = { method: 'GET',
  url: 'https://api.hubapi.com/contacts/v1/contact/vid/12627374/profile',
  qs: { hapikey: 'demo' }
}
request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

我只是不确定该代码应该在哪里,以便我可以动态提取数据。它应该放在 gatsby-browser.js 下吗?还是我需要一个额外的模块,比如 Axios 或 Express ?还是它在我的 AWS 安装中的某个地方?

谢谢!

【问题讨论】:

    标签: gatsby hubspot


    【解决方案1】:

    我在 return 语句之前的组件中使用这个获得了交易数据:

    export default function AppHub () {
    
        const [deals, setDeals] = useState([]);
        
        useEffect(() => {
        
            fetch(`https://api.hubapi.com/crm/v3/objects/deals?hapikey=YOURKEYHERE&limit=100`,
            )
            .then(response => response.json()) // parse JSON from request
            .then(dealsapi => {
                console.log(dealsapi);
                setDeals(dealsapi.results);
            })
            .catch(console.error);
        }, []);
    

    【讨论】:

      猜你喜欢
      • 2014-08-13
      • 2014-11-08
      • 2011-04-08
      • 1970-01-01
      • 2017-03-08
      • 2021-05-07
      • 1970-01-01
      • 2010-09-10
      相关资源
      最近更新 更多