API Key Generation  Topic is solved

Discussions relating to the REST API of Jiwa 7.

API Key Generation

Postby SBarnes » Tue Apr 21, 2020 6:59 pm

Does the web api have a route to generate/return a Debtor API key, we have a client who wants the ability to generate an api key for the logged in debtor within their web store where the customer would then be able to use the generated api key for a specific set of routes related to file export?

If the route doesn't exist could you provide some sample code for generating the key?

I wouldn't be considering this except the customer wants to do it and the web store and api will be running under SSL, I may also implement some sort of TFA to protect it as well.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: API Key Generation

Postby Mike.Sheen » Tue Apr 21, 2020 11:09 pm

SBarnes wrote:Does the web api have a route to generate/return a Debtor API key, we have a client who wants the ability to generate an api key for the logged in debtor within their web store where the customer would then be able to use the generated api key for a specific set of routes related to file export?

If the route doesn't exist could you provide some sample code for generating the key?

I wouldn't be considering this except the customer wants to do it and the web store and api will be running under SSL, I may also implement some sort of TFA to protect it as well.


No, we don't have a route to generate or return a Debtor API key. It would be fairly simple to do - the debtor business logic does have the ability to do that, so it would be a matter of creating plugin to add that route, which would just invoke the necessary method and serialising a response.

We can provide a sample plugin of how to add a route to generate a debtor API key, and retrieve a key - but we are a little pressed for time ATM, so you may need to be a bit patient.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: API Key Generation  Topic is solved

Postby SBarnes » Wed Apr 22, 2020 8:00 am

Mike.Sheen wrote:We can provide a sample plugin of how to add a route to generate a debtor API key, and retrieve a key - but we are a little pressed for time ATM, so you may need to be a bit patient.


Hi Mike,

As always thanks for the response, from that I was able to follow my nose and found that the following with modification should get the key created, given you are under the pump I think I can get this resolved from here.

Code: Select all
                   APIKey aPIKey = this.Manager.CollectionItemFactory.CreateCollectionItem<APIKey>();
                    aPIKey.Staff.Search(this, "");
                    this.Debtor.APIKeys.Add(aPIKey);


                    APIKey item = this.Debtor.APIKeys[str1];
                    item.KeyValue = item.GenerateNewKey();



In other words create the api key object, set the staff member as required, add it to the collection on the debtor which I am assuming will let it know the debtor needed at save, call generate new key and then save the debtor.

Putting it in a service for the api in a plugin should be fairly straight forward from there.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1618
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to REST API

Who is online

Users browsing this forum: No registered users and 1 guest

cron