Autodesk Platform Services - Tutorial Trouble

Autodesk Platform Services - Tutorial Trouble

retug_austin
Enthusiast Enthusiast
1,075 Views
9 Replies
Message 1 of 10

Autodesk Platform Services - Tutorial Trouble

retug_austin
Enthusiast
Enthusiast

Not sure if this is the correct spot to post APS questions, feel free to move this around if this is the wrong spot.

I am following the Autodesk APS example here:

https://tutorials.autodesk.io/tutorials/simple-viewer/data

Everything so far has been going well, but when I get to part 3 and the try it out step:

"Start (or restart) the app as usual, and navigate to http://localhost:8080/api/models in the browser. The server should respond with a JSON list with names and URNs of all objects available in your configured bucket."

Navigating to "http://localhost:8080/api/models" results in 403 error code on my end.

Not sure where I've gone wrong. Any ideas?

image 6 - part 3 giving 403 error code.png

 

Full error message:

"AxiosError: Request failed with status code 403
at settle (C:\Users\16142\Desktop\Retug\Own Work\APS Tutorial\node_modules\axios\dist\node\axios.cjs:1967:12)
at IncomingMessage.handleStreamEnd (C:\Users\16142\Desktop\Retug\Own Work\APS Tutorial\node_modules\axios\dist\node\axios.cjs:3066:11)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:\Users\16142\Desktop\Retug\Own Work\APS Tutorial\node_modules\axios\dist\node\axios.cjs:3877:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
application.js:647
Process exited with code 1"

Thanks!

0 Likes
Accepted solutions (1)
1,076 Views
9 Replies
Replies (9)
Message 2 of 10

retug_austin
Enthusiast
Enthusiast

Seems like a problem with Client ID and Client Secret I think?

 

I went through the last part and I get this popup:

retug_austin_0-1710106898383.png

Code is uploaded on github.

https://github.com/retug/APSExamples/tree/main/simpleViewer

my .env file looks like this (not uploaded to hide Client ID and Client Secret) :

APS_CLIENT_ID="<_____________________________________________>"
APS_CLIENT_SECRET="<_________________________________________>"
 
I got my client ID and client secret off the APS application page.

Edit More Info, error gets thrown at viewer.js, at the getAccessToken function.

async function getAccessToken(callback) {
try {
const resp = await fetch('/api/auth/token');
if (!resp.ok) {
throw new Error(await resp.text());
}
const { access_token, expires_in } = await resp.json();
callback(access_token, expires_in);
} catch (err) {
alert('Could not obtain access token. See the console for more details.');
console.error(err);
}
}


Thanks!

 

0 Likes
Message 3 of 10

retug_austin
Enthusiast
Enthusiast

Ok, some progress, still confused, but I missed a step on the tutorial.

https://aps.autodesk.com/en/docs/oauth/v2/tutorials/get-2-legged-token/

I replaced the viewer.js getAccessToken function with these lines of code that were generated by ChatGPT:

 

async function getAccessToken(callback) {
    try {
       
        const clientId = "______________________________________";
        const clientSecret = "_________________________________";

        // Base64 encode the client ID and client secret
        const concatword = clientId + ":" + clientSecret;
        const base64word = btoa(concatword);

        const url = 'https://developer.api.autodesk.com/authentication/v2/token';
        const body = new URLSearchParams({
            'grant_type': 'client_credentials',
            'scope': 'data:read'
        });

        const resp = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': 'Basic ' + base64word
            },
            body: body
        });

        if (!resp.ok) {
            throw new Error(await resp.text());
        }

        const { access_token, expires_in } = await resp.json();
        callback(access_token, expires_in);
    } catch (err) {
        alert('Could not obtain access token. See the console for more details.');
        console.error(err);
    }
}

 

 

This seems to work, but not in the intended way the tutorial wants.
I am bit lost in the documentation at step 2:

https://aps.autodesk.com/en/docs/oauth/v2/tutorials/get-2-legged-token/

What does "Call the POST token endpoint" mean and how do I do that? Where am I doing this in the tutorial that is uploaded on github? All of this likely can be attributed to my lack of knowledge with web development, so apologies for the likely very basic questions.
 
0 Likes
Message 4 of 10

jeremy_tammik
Alumni
Alumni
Accepted solution

Well sorry to say, just as you surmised, this is not the right place for this discussion. Please refer to the official APS help channels, e.g., via:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 10

retug_austin
Enthusiast
Enthusiast

Thanks @jeremy_tammik 

 

stackoverflow... I'm ready to be banned for my low effort question 😎.

0 Likes
Message 6 of 10

jeremy_tammik
Alumni
Alumni

Many APS questions there are picked up by my colleagues in the DAS developer support and advocacy team, and I don't think  we ban anyone... at least I don't... good luck!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 10

retug_austin
Enthusiast
Enthusiast

I say this in jest, back in my early years of learning python ~8 years ago now, I made what I will admit was a very low effort post on stackoverflow.

I came back the next day to a very large red warning on my computer screen saying I had banned from stackoverflow for 48 hrs due to my egregious actions. 

 

I felt really bad about myself for some silly internet points.

0 Likes
Message 8 of 10

jeremy_tammik
Alumni
Alumni

I must admit I sometimes wish we applied such rules here in this forum as well  🙂

  

But I am also happy that we get by with hardly any rules at all.

  

Anyway, I think we are on the verge of being able to set up an AI to handle all simple and repetitive questions automatically, and forward only the interesting ones to more advanced handlers, and also flag the content accordingly, so that passive readers can be informed up front what is worth looking at and what not.

  

If done right that could eliminate the need for any rules and improve the quality of the forum and the discussions at the same time.

  

Wishful thinking? Optimistic? We'll see, and I am looking forward to seeing...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 9 of 10

retug_austin
Enthusiast
Enthusiast

 


@jeremy_tammik wrote:

Anyway, I think we are on the verge of being able to set up an AI to handle all simple and repetitive questions automatically, and forward only the interesting ones to more advanced handlers, and also flag the content accordingly, so that passive readers can be informed up front what is worth looking at and what not.


I like it, should be a good way to cut down on spam and repeat questions. It can go too far though. I made post on stackoverflow yesterday about this problem, and it took me a solid 15 mins of editing to make the AI not flag it is as spam.

I realized I was using a much more conversational tone as compared to the typical stackoverflow required tone of "X is not working, I have tried Y, looking for solution Z".

Rewording the post took some time and likely did yield a much better post, but it was almost too much AI control.

I am sure you can find the right balance on your end.

0 Likes
Message 10 of 10

jeremy_tammik
Alumni
Alumni

You can use the AI to reformulate the post for you, so that the other AI at the other end will find it acceptable  🙂

  

Check out "ai email writer" and "ai email summariser"... I have seen some funny descriptions of how the human writes a few sloppy words, the AI creates a beautiful and verbose message from that, and the other human at the other end uses the AI to summarise the verboseness into a very few (not so sloppy) terse words.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open