【发布时间】:2021-09-17 14:36:03
【问题描述】:
所以我试图通过这个 api 在我的 git repo 中创建一个新文件,我在我的 react 代码库中公开了这个文件,我得到了 403 错误?让我知道我哪里错了。
var bodyData = {
token: "**********",
ref: "main",
branch: "demo",
commit_message: "create a new file",
content: "some content"
};
fetch("https://gitlab.com/api/v4/projects/27622003/repository/files/myfile1%2Etxt", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(bodyData),
})
.then((response) => response.json())
.then((data) => {
console.log("response:", data);
})
.catch((error) => {
console.error("Error:", error);
});
【问题讨论】:
-
我不熟悉 gitlab,所以这不是答案,但是根据我的经验,错误 403 意味着您提供了正确的令牌,但是您的 API 无权调用 Gitlab。我假设您需要执行一个步骤来允许您的 API 进行调用
标签: reactjs gitlab gitlab-api