cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
krubin
Level 7

Trying to use Rest API to Register the Activation ID from Postman

Jump to solution

Hello,

I am trying to use Rest API to Register the Activation ID from Postman. The reply is 404

<p><b>description</b> <u>The requested resource is not available.</u></p>

The entitlement with the activation id is deployed. See attachment .

url: https://<domain>-ns-uat.flexnetoperations.com/uai/2.0/devices/registrations 

header: includes bearer token for the Json Web Token

Body:

{

"activationId": "ACT01-BMSClient",

"id": "KenPC",

"idType": "STRING",

"identityName": "UAIDeviceIdentity",

"publisherName": "bloom"

}

Thank you,

Ken

0 Kudos
(1) Solution
jberthold
Revenera Moderator Revenera Moderator
Revenera Moderator

Hi Ken,

I'll email you my Postman collection.  I can't fully test without your JWT but I do get a valid response.

Thx,

Jim

View solution in original post

(8) Replies
jberthold
Revenera Moderator Revenera Moderator
Revenera Moderator

Hi Ken,

Something must be wrong with your request.  I don't have your JWT but tried sending a similar request to your notification server and got back a valid Polling ID.  When I check with the response with the Polling ID I got an invalid signature (as expected since I don't have your JWT).

 

RegTest.jpg

You can always try the online Swagger page to directly test the UAI Rest APIs (UAT URL below):

https://{yoursite}-ns-uat.flexnetoperations.com/uai/documentation/swagger-ui.html

Thanks,

Jim

0 Kudos

Hi Jim,

That JWT works for me still doing an update post. One thing that I see is that you have ten items in your header and I have 9. My header with the JWT crossed out is attached below. Perhaps that is where the issue lies?

 

Thank you,

Ken

0 Kudos
jberthold
Revenera Moderator Revenera Moderator
Revenera Moderator

Hi Ken,

I'll email you my Postman collection.  I can't fully test without your JWT but I do get a valid response.

Thx,

Jim

Thanks so much Jim! I received a successful response on Swagger and also using C# code, which is the most important. It would be curious to see your Postman collection.

0 Kudos

Can you please share C# sharp code as I am also facing the same issue.

0 Kudos

Generic C# code.

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.BaseAddress = new Uri("https://youraddress-ns-uat.flexnetoperations.com/"); //This is for UAT environment

client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", jsonWebToken); //Create a JSON Web Tokeb
ActivationRegistration activateRegistration = new ActivationRegistration(activationId, pcId, "STRING", identityName, publisherName);

HttpResponseMessage response = client.PostAsJsonAsync(
"uai/2.0/devices/registrations", activateRegistration).Result;

The ActivationRegistration class is generated on the https://json2csharp.com/ site. Use the JSON results example in Flexnet operations manual for Registration for the JSON.

I have renamed the classes generated.

The activation ID is setup by administration in the Flexnet portal, related to Entitlements.You choose the pcId. This will be used subsequently for updates.
The IdentityName and publisherName values can be found in the Flexnet Portal under Administer/Publishers and Administer/Indentity

0 Kudos

Thank for sharing a code.

Actually how will get a JSON Web token so that I can call further API's. Can you please help in that?

0 Kudos

I think I generated the public and private keys with these steps, tried a few different ways a while back.

Step 1 To Generate Public and Private Keys

start cmd prompt

openssl genrsa -out UAIPrivate.pem 2048

cmd /k openssl rsa -inform PEM -outform PEM -in UAIPrivate.pem -pubout -out UAIPublic.pem
To create Public and private keys.


Step 2 Generate Json Web token

The Python program below was given to me from Revenera. For some reason it only works in the Jupiter Notebook, which is part of the Anaconda installation.
It did not work in the Spyder environment. I don't know how to do this from other languages. Please make sure that the public and private key file names
are correct in the program.

import jwt
import datetime
import sys

# Execute the python script by invoking the following # from the command line: python3 SignJWT.py SaaSDemoPrivate.pem

# Read the supplied private key file


#private_key = open('jwtRS256.key', 'r')
path = 'C:\\python\\revenera\\UAIPrivate.pem'

with open(path, 'r') as private_key:
private_key_string = private_key.read()
private_key.close()

# Setup the JWT's payload
payload = { 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=3650) }

# Use PyJWT to encode a sign a JWT
token = jwt.encode( payload, private_key_string, algorithm='RS256')

# Present token to the user
print('Bearer ' + token.decode('ASCII'))