0

I am trying to change the required engine version of an AppPackage that I have posted using v2 of the Design Automation API.

I've tried using Postman and the Forge Node Client. I'm using the Forge documentation as a reference.

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

My credentials are correct and I have a valid token, but for some reason I keep getting a 404 Not Found status and an error that says "AppPackage with the name MyPlugin doesn't belong to you. You cannot operate on AppPackage you do not own." Also, I get the same message when I try to delete or update the AppPackage.

That's really weird because I definitely own this AppPackage. I uploaded it with these same credentials and I can view it by doing a GET request to view all of my AppPackages. Furthermore, the name of the AppPackage is correct and I specified the right scope (code:all) when I authenticated.

Why does Design Automation think this AppPackage doesn't belong to me and why can't I patch, update, or delete it?

UPDATE 3/28/2019: Setting the resource value still results in the same error

UPDATE 4/2/2019: Getting a fresh upload URL doesn't work either. I get an internal server error saying "Object reference not set to an instance of an object."


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

  • Can you please put the new/modified app package to aws upload URL that you've retrieved from [GetUploadUrl](https://developer.api.autodesk.com/autocad.io/us-east/v2/AppPackages/Operations.GetUploadUrl), and then run PATCH appackage. See if that helps. – Madhukar Moogala Apr 02 '19 at 08:44
  • Still unsuccessful. I'm not longer getting the "doesn't belong to you" error, but I am getting an "Object reference not set to an instance of an object" error. I've updated my question with the latest code snippet. – Andrew McEwen Apr 02 '19 at 15:48
  • I just tried PATCH apppackage, works at my [end](https://ibb.co/XLY0c08), can you please show me JSON pay load ? I believe something trivial is missing. – Madhukar Moogala Apr 03 '19 at 07:21
  • { "uri": "https: //developer.api.autodesk.com/autocad.io/us-east/v2/AppPackages(%27MyPlugin%27)", "method": "PATCH", "qs": {}, "timeout": 60000, "body": { "Resource": "https: xxxxxxx", "RequiredEngineVersion": "23.0" }, "json": true, "headers": { "Content-Type": "application/json", "Accept": "application/vnd.api+json,application/json", "Authorization": "Bearer xxxxxxx" }, "agentOptions": { "secureProtocol": "TLSv1_2_method" } } – Andrew McEwen Apr 03 '19 at 14:25
  • ^ I'm using the Forge Node client and those are the request parameters that I console logged from the source code. – Andrew McEwen Apr 03 '19 at 14:26
  • There's a typo in the JSON above. I'm actually trying to set the required engine version to "22.0" not "23.0". According to the v2 docs, version 23.0 is not supported. – Andrew McEwen Apr 04 '19 at 17:26

2 Answers2

0

When calling PATCH the "Resource" property must be set. It can be set to the same URL as the one you receive from GET but it must be present and valid.

Albert Szilvasy
  • 461
  • 3
  • 5
0

This should work:

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);
    }

})();
Albert Szilvasy
  • 461
  • 3
  • 5
  • Note that the successful PATCH operation returns 204. – Albert Szilvasy Apr 20 '19 at 18:14
  • This code is working for all of my AppPackages except one. I can't do anything with that one AppPackage because apparently it doesn't belong to me. Something must be wrong with the resource URL. Strangely enough, when I navigate to the resource URL in my browser, the AppPackage file downloads right away and it's the size I would expect it to be. – Andrew McEwen Apr 23 '19 at 20:29
  • I finally patched the AppPackage. I have two Forge accounts, one for development and one for production. Both accounts have an AppPackage with the same name. I noticed that the production AppPackage was public, and the development AppPackage was private. When I changed the production AppPackage to private, I was able to patch the development AppPackage. I didn't do anything else, so I'm assuming that this was the solution. Can you confirm? – Andrew McEwen Apr 24 '19 at 16:28