Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Entitlement API

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
brad.bylls
414 Views, 10 Replies

Entitlement API

I have recently submitted a WinOS python add-in to the app store with 30 day trial and purchase. 

They said they removed the 30 day trial because I didn't integrate the Entitlement API

I would like to do that but can't find enough information on what it exactly is and how to integrate it. 

Please help so I can get it in the store finally. 

Thank you

Brad Bylls
10 REPLIES 10
Message 2 of 11
BrianEkins
in reply to: brad.bylls

I believe this is the official documentation for the entitlement API.

https://damassets.autodesk.net/content/dam/autodesk/www/adn/pdf/entitlement-api-for-desktop-apps.pdf

 

I was able to write a simple implementation of this in Python and the Fusion API as shown below.  There are two items you need to input into the request; the user ID and the app ID.  You can get the current user ID using the API as shown below. The app ID you can get from the app store. For existing apps you'll see it in the URL when you got to its page. For an unpublished app, I'm not sure how you get its ID.

 

import adsk.core, adsk.fusion, adsk.cam, traceback
import urllib
import json

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface

    try:
        userID = app.userId
        appID = '3534533763590670806'
        url = f'https://apps.autodesk.com/webservices/checkentitlement?userid={userID}&appid={appID}'
        response = urllib.request.urlopen(url) 
        jsonb = response.read() 
        jsont = jsonb.decode("utf-8") 
        json_dict = json.loads(jsont) 

        if json_dict['IsValid']:
            ui.messageBox('The license is valid.')
        else:
            ui.messageBox('Invalid license.\nMessage: ' + json_dict['Message'])
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 11
brad.bylls
in reply to: BrianEkins

Thanks Brian.

I think I understand how it works.

What I don't get is where the code will go and how it is triggered.

Not clear to me in the documentation either. 

Brad Bylls
Message 4 of 11
BrianEkins
in reply to: brad.bylls

That's a good question and makes me wonder how they know your app isn't using the entitlement API. Maybe they're checking if the entitlement API is being hit when your app is run.

 

I think there are a couple of ways to use it. One is to check it in the run function and if the entitlement fails, then you don't do anything in the run. One thing to be aware of if you do this though is that you can't do the actual entitlement check at the time your add-in is loaded at Fusion start-up time. The user ID isn't available until Fusion goes online, which is usually a few seconds later. I discovered this the hard way. A workaround is to connect to the Application.onlineStatusChanged event and then to do the check there where you will have access to the user ID.

 

If the check fails and the user isn't entitled to your app you can choose to still display your command button but when they click it, it can display a message telling them the trial has expired and they need to purchase it to continue. Or you could remove all your UI so your commands aren't available at all.  The first option seems nicer.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 11
brad.bylls
in reply to: BrianEkins

Hello Brian,

 

I just heard back from Raghavendra Kammar at the Autodesk App Store who said that the Entitlement API does not work with Fusion 360 and I should consider 2 different add-ins.

One add-in for trial and one for purchase.

Doesn't make sense to me but . . .

Thanks.

Brad Bylls
Message 6 of 11
BrianEkins
in reply to: brad.bylls

That doesn't make sense to me either. I don't see why Fusion apps would be different than the other products.

 

I have one app that I distribute through the app store, but I don't use the store to sell or license it and wrote my own backend for that. What the user is installing is the full software but it runs in a trial mode for 60 days or until they enter a license key, which they purchase from my website.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 7 of 11
brad.bylls
in reply to: BrianEkins

I tried running your code as a script just to see what happens.

The appID that I used is from my app in the store (unpublished)

This is the error I got:

Untitled.png

Brad Bylls
Message 8 of 11
BrianEkins
in reply to: brad.bylls

It seems something is coming back that's not expected from the call. For testing, you can just try using the following URL in your browser, where you'll change userID to your ID and the appID to your app id. The resulting JSON will be shown in the browser and you can possibly see what's wrong.

 

https://apps.autodesk.com/webservices/checkentitlement?userid={userID}&appid={appID}

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 9 of 11
brad.bylls
in reply to: BrianEkins

I entered:

https://apps.autodesk.com/webservices/checkentitlement?userid={XNM5MWQE7JRP}&appid={2588623515668137...}

This is what was returned:

{"UserId":"{XNM5MWQE7JRP}","AppId":"{2588623515668137326}","IsValid":false,"Message":"Ok"}

Not knowing anything about JSON, I am guessing 4 values were returned?

The first 2 just validating the ID's

I would think "IsValid" should be true?

Brad Bylls
Message 10 of 11
BrianEkins
in reply to: brad.bylls

That's right, there were four properties returned. Here it is formatted so it's easier to read.

{
    "UserId": "{XNM5MWQE7JRP}",
    "AppId": "{2588623515668137326}",
    "IsValid": false,
    "Message": "Ok"
}

 

There is a problem in your example in that the userId and AppId should not be wrapped in braces. Here's an example of a valid call that returns true.

 

https://apps.autodesk.com/webservices/checkentitlement?userid=6X3SR6SGGYQN&appid=3534533763590670806

 

When I removed the braces from yours, it fails and send back the HTML for a failure page. I would have expected it to still succeed even if the ID's are invalid but return false for IsValid but it must be doing some evaluation on the ID's. I did some other random changes to the ID's and sometimes it would work and send back the JSON and other times I would get back the web page.  At least it does appear to always work if I pass in a valid product and user ID, but as I said before, in my case I'm not using it so I don't have a lot of experience with it.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 11 of 11
brad.bylls
in reply to: BrianEkins

Brian,

I substituted your numbers in my code and it works and returns IfValid: true and then the message box saying it is a valid license.

When using my numbers I get the error webpage.

I got my numbers from the app store and copied and pasted them into my code.

I'm thinking maybe because my app is not published yet is why it is not working.

I have an email into them with that question.

Thanks for the help and letting me use some good numbers to locate the problem.

Brad Bylls

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report