我是 BigCommerce 的新手,我需要对网站的注册表单进行一些更改,这包括使用自定义 Apex API 来显示学校名称列表,然后用户可以从选择列表中选择作为他们的学校。
我有 Salesforce 身份验证代码,以及 API 调用在本地节点中运行良好,但是将此代码添加到包含注册表单的页面不会像在本地那样在控制台中打印任何内容。我确定我缺少一些步骤,但不知道该怎么做。我知道 BigCommerce 不能访问服务器端,所以这一切都必须在客户端完成,对吗?
下面是我的代码示例,实际上没有透露任何凭据。这取自JSForce 文档。
// Salesforce authentication
var jsforce = require('jsforce');
var conn = new jsforce.Connection({
// you can change loginUrl to connect to sandbox or prerelease env.
// loginUrl : 'https://test.salesforce.com'
});
conn.login(username, password, function(err, userInfo) {
if (err) { return console.error(err); }
// Now you can get the access token and instance URL information.
// Save them to establish connection next time.
console.log(conn.accessToken);
console.log(conn.instanceUrl);
// logged in user property
console.log("User ID: " + userInfo.id);
console.log("Org ID: " + userInfo.organizationId);
// ...
});
// Apex REST API Call
// body payload structure is depending to the Apex REST method interface.
var body = { title: 'hello', num : 1 };
conn.apex.post("/MyTestApexRest/", body, function(err, res) {
if (err) { return console.error(err); }
console.log("response: ", res);
// the response object structure depends on the definition of apex class
});