安装 SDK
Node.js SDK使用说明:https://help.aliyun.com/document_detail/57342.html
package.json:
{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@alicloud/pop-core": "^1.7.7"
}
}
调用 Codeup API
以 CreateRepository 为例:
创建个人访问令牌见 个人访问令牌
var ROAClient = require('@alicloud/pop-core').ROAClient;
var client = new ROAClient({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessSecret>',
endpoint: 'https://codeup.cn-hangzhou.aliyuncs.com',
apiVersion: '2020-04-14'
});
// 1. 请求方法
var httpMethod = 'POST';
// 2. 接口Url
var uriPath = '/api/v3/projects';
// 3. 接口query参数
var queries = {
"RegionId": "cn-hangzhou",
"OrganizationId": "<OrganizationId>"
};
// 4. 接口body参数
var body = `{
"name": "<RepoName>",
"path": "<RepoPath>",
"visibility_level": 10,
"namespace_id": 123
}`;
var headers = {
"Content-Type": "application/json"
};
var requestOption = {};
client.request(httpMethod, uriPath, queries, body, headers, requestOption).then((res) => {
console.log(res);
}, (err) => {
console.log(err);
})
文档内容是否对您有帮助?