0

我正在尝试更改使用设计自动化 API v2 发布的 AppPackage 所需的引擎版本。

我试过使用 Postman 和 Forge Node Client。我使用 Forge 文档作为参考。

https://forge.autodesk.com/en/docs/design-automation/v2/reference/http/AppPackages (':id')-PATCH/

我的凭据是正确的,并且我有一个有效的令牌,但由于某种原因,我不断收到 404 Not Found 状态和一个错误,上面写着“名为 MyPlugin 的 AppPackage 不属于您。您无法在您不拥有的 AppPackage 上操作。” 此外,当我尝试删除或更新 AppPackage 时,我会收到相同的消息。

这真的很奇怪,因为我绝对拥有这个 AppPackage。我使用这些相同的凭据上传了它,我可以通过执行 GET 请求来查看我的所有 AppPackages。此外,AppPackage 的名称是正确的,并且我在进行身份验证时指定了正确的范围(代码:all)。

为什么 Design Automation 认为这个 AppPackage 不属于我,为什么我不能修补、更新或删除它?

更新 3/28/2019:设置资源值仍会导致相同的错误

更新 4/2/2019:获取新的上传 URL 也不起作用。我收到一个内部服务器错误,提示“对象引用未设置为对象的实例”。


const ForgeSDK = require('forge-apis');
const oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, SCOPES);
const appPackageApi = new ForgeSDK.AppPackagesApi();

const getToken = () => {
    return oAuth2TwoLegged.authenticate();
};

const getUploadURL = () => {
    return appPackageApi.getUploadUrl(oAuth2TwoLegged, oAuth2TwoLegged.getCredentials());
};

const patchPackage = (id, url) => {

    const appPack = {
        Resource: url,
        RequiredEngineVersion: APP_PACKAGE_REQUIRED_ENGINE
    };

    return appPackageApi.patchAppPackage(id, appPack, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials());
};


(async () => {

    try {
        const token = await getToken();
        const url = await getUploadURL();
        const patchPackRes = await patchPackage(APP_PACKAGE_ID, url);

        if (patchPackRes.statusCode == 201)
            console.log('Patch package succeeded!');
        else
            console.log('Patch package failed!' + patchPackRes.statusCode);

    } catch (ex) {
        console.log('Exception  :(');
        console.log(ex);
    }

})();

在此处输入图像描述

在此处输入图像描述

4

2 回答 2

0

这应该有效:

const ForgeSDK = require('forge-apis');
const oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, SCOPES);
const appPackageApi = new ForgeSDK.AppPackagesApi();

const getToken = () => {
    return oAuth2TwoLegged.authenticate();
};

const getUploadURL = async (id) => {
    const app =  await appPackageApi.getAppPackage(id, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials());
    return app.body.Resource;
};

const patchPackage = (id, url) => {

    const appPack = {
        Resource: url,
        RequiredEngineVersion: APP_PACKAGE_REQUIRED_ENGINE
    };

    return appPackageApi.patchAppPackage(id, appPack, oAuth2TwoLegged, oAuth2TwoLegged.getCredentials());
};


(async () => {

    try {
        const token = await getToken();
        const url = await getUploadURL(APP_PACKAGE_ID);
        const patchPackRes = await patchPackage(APP_PACKAGE_ID, url);

        if (patchPackRes.statusCode == 201)
            console.log('Patch package succeeded!');
        else
            console.log('Patch package failed!' + patchPackRes.statusCode);

    } catch (ex) {
        console.log('Exception  :(');
        console.log(ex);
    }

})();
于 2019-04-20T18:14:10.790 回答
0

调用 PATCH 时,必须设置“资源”属性。它可以设置为与您从 GET 收到的 URL 相同的 URL,但它必须存在且有效。

于 2019-03-27T05:36:15.930 回答