How to get an api key from sys_properties to REST Message

chadlockwood
Kilo Sage

I need to be able to maintain an API key encrypted and apply it to an outbound REST Message. 

I thought that it should be easy enough to say the API key as a password in sys_properties the call it from the REST Message header value (x-api-key) as:

javascript:gs.getProperty("api_key");

Realizing that it may require a little decrypting, I first saved the API key as a string. However, the REST Message doesn't appear to be able to pull the value from the property on the fly. Is there another way to do this?

1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

If I recall correctly that should just get the value.

You shouldnt need to decrypt it.

I am using a property in the same way but I always go recordless outbound rest.

 

var restMessage = new sn_ws.RESTMessageV2();
restMessage.setBasicAuth(gs.getProperty('thousandeyes.user'), gs.getProperty('thousandeyes.pass'));
restMessage.setHttpMethod("get");

View solution in original post

4 REPLIES 4

Jace Benson
Mega Sage

If I recall correctly that should just get the value.

You shouldnt need to decrypt it.

I am using a property in the same way but I always go recordless outbound rest.

 

var restMessage = new sn_ws.RESTMessageV2();
restMessage.setBasicAuth(gs.getProperty('thousandeyes.user'), gs.getProperty('thousandeyes.pass'));
restMessage.setHttpMethod("get");

Jace,

Thanks for the reply. I was trying to use the Outbound REST form to build my REST message. I was unable to use getProperty on that form to get the api key into the message. At first, I decided to just hardcode the api key onto the form. That worked, of course, but wasn't what I wanted. So I switched to creating a Script Include with RESTMessageV2 and calling getProperty from there. That is a much better, reusable solution.

Rick Mann
Tera Expert

Hello Jace

I'm working to setup an Outbound REST message that will use and API key to talk with Dell TechDirect.  I'm new to use API Key authentication and curious to see how you would configure the key within the Authentication type of the message record.  I see in your script example where you are setting BasicAuth.  Do I need to setup a BasicAuth profile to store the key?

I will look to script the message at a later point, I'm just working to establish connectivity right now.

Thanks.

Yea, if you are using some api key, or custom header, can can call that out with setRequestHeader, i'd tell it to use a sys_properties record if thats the case.  If you can, it is probably better to use the `setAuthenticationProfile` but thats for basic auth or oauth if I recall correctly.

https://blog.jacebenson.com/restmessagev2/#setauthenticationprofile

Developer docs