为什么我不能修补,更新或删除我创建的AppPackage?

时间:2019-03-26 20:36:58

标签: autodesk-forge autodesk-designautomation

我正在尝试更改使用Design Automation 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不属于我,为什么我不能修补,更新或删除它?

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

2019年4月2日更新:获取新的上传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);
    }

})();

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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);
    }

})();