Aurigma 客户 Canvas SDK - storefront API 客户端
这个模块是 Storefront API 的 Axios API 客户端,它是其中的一部分 顾客的相片 网络对打印系统. 您应该熟悉其服务并了解如何使用其API。 欲了解更多客户的Canvas及其服务,请参见: 获得其文件的起始部分。 。 。 .
API 客户端是自动生成的 NSwag 工具。如果由于任何原因,此 API 客户端对您不起作用,请自行使用 Swagger 文档生成它 客户的 Canvas API 网关。 。 。 .
先决条件
要能够使用此软件包,需要满足以下要求: 1
- 你一定有客户的账户.
- 您需要在 Javascript\ Typescript 应用程序中使用它 .
关于其他平台,请参见 后端服务 在客户的Canvas文档中的文章.
使用量
作为正则 npm 软件包安装 :
npm install @aurigma/axios-storefront-api-client
节点Js
如您所解释的那样,通过您的后端接收访问令牌 文档 把它交给你的应用程序.
const storefront = require("@aurigma/axios-storefront-api-client");
const axios = require("axios").default;
// You need to create external app in BackOffice with required scopes to receive clientId\clientSecret
// https://customerscanvas.com/dev/getting-started/about-backend-services.html#authorization
const clientId = "";
const clientSecret = "";
const apiUrl = "https://api.customerscanvashub.com/";
const getToken = async (clientId, clientSecret) => {
const requestConfig = {
method: "post",
url: apiUrl + "connect/token",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
data: new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
grant_type: "client_credentials",
}),
};
const response = await axios(requestConfig);
return response.data["access_token"];
};
const token = await getToken(clientId, clientSecret);
然后用这个符号调用 ApiClients 方法:
const config = new storefront.ApiClientConfiguration();
config.apiUrl = apiUrl;
config.setAuthorizationToken(token);
const buildInfoClient = new storefront.BuildInfoApiClient(config);
const buildInfo = await buildInfoClient.getInfo();
const productSpecificationsApiClient =
new storefront.ProductSpecificationsApiClient(config);
const productSpecifications = await productSpecificationsApiClient.getAll();
前端
你应该从你的后端取回访问令牌 上面怎么解释的.
import {
ApiClientConfiguration,
BuildInfoApiClient,
ProductSpecificationsApiClient,
} from "@aurigma/axios-storefront-api-client";
// A token should be received from your backend
const token = "";
// In general you can use "https://api.customerscanvashub.com" as a base api url.
// But this url may be different for on-premises version of Customer's Canvas
const baseApiUrl = "https://api.customerscanvashub.com";
const config = new ApiClientConfiguration();
config.apiUrl = baseApiUrl;
config.setAuthorizationToken(token);
const buildInfoClient = new BuildInfoApiClient(config);
buildInfoClient.getInfo().then((data) => console.log(data));
const productSpecificationsClient = new ProductSpecificationsApiClient(config);
productSpecificationsClient.getAll().then((data) => console.log(data));
为了解本模块中有哪些其他客户,请参见: 存储前置 API 参考。 。 。 .
注:每个客户的类名称形成为: 客户端NameApiClient, 例如: ApiClient, 例如 :.
BuildInfo- > (中文)BuildInfoApiClient等 (中文(简体) ).