Skip to main content
Solved

Call a web service - Post to get a bearer token

  • 17 June 2024
  • 6 replies
  • 78 views

Hello,

I need to Post to an API URL sending my username and password to get a bearer token returned. I’m struggling with the syntax needed to send form data plus these 2 inputs. I’ve used Postman to test my credentials and the URL. I get a 200 status code and the token is returned. However, I haven’t been able to get it to work within Nintex itself.

Can someone please tell me what belongs in the Request headers and Request content boxes to make this work?

Kind regards,

Jenny

 

6 replies

Userlevel 6
Badge +13

Hi @jennym 

The best method for doing this would be to build out an xtension to store the call procedure, then it can be added to both forms and workflows and Nintex will handle the token handshake for you.

 

https://help.nintex.com/en-US/xtensions/02_BuildOpenAPI/01_Basic/PRC_01Find_API.htm

Here is an example xtension which performs this using oauth2: 

https://gallery.nintex.com/t/linkedin

 

Jake 

Userlevel 2
Badge +7

Hi @jennym 

I found the example code here useful to see what headers to send,

https://help.nintex.com/en-us/k2cloud/userguide/current/Content/Runtime/WF-REST-API/WF-REST-API-Authentication.htm

example,

  request.setRequestHeader("Content-Type", "application/json");
  request.setRequestHeader("Authorization", `Bearer ${token}`);
Badge +1

Thanks, both. I appreciate the answers. For this instance though, I’d like the quick and easy answer on how to format form fields to send through the basic fields first, please. I don’t want to build an extension if all I’m trying to do is post a username and password to a URL and retrieve a token as the variable. I’ve hard-coded the token from Postman in my next call and gotten a 200. Can you please share the syntax to do this in the Request headers or Request content fields? Thanks

Userlevel 2
Badge +6

Hi @jennym 

What service are you calling against?  The configuration of Web Services is dependent on what API you’re calling so without what API you’re calling it’s not possible to know what configuration you’d need.

I’d also recommend looking at building an Xtension rather than using a pure web service buildout (I assume you’re calling another web service after this using the bearer token).  For the documentation on how to build out Xtensions you can look here: https://help.nintex.com/en-US/xtensions/Home.htm

Lastly you might want to check the Nintex Gallery to see if someone else has already built a connector to the service you're calling: https://gallery.nintex.com/search?search_term=&capability=10005&industry=&department=&partner=&capabilities=connectors&sortBy=&aggregation={}&index=[]&currentPage=1

Userlevel 2
Badge +6

And Jake beat me to it 

Userlevel 4
Badge +10

@jennym 

If you’d like an example of a “Call a Web Service” action that retrieves a bearer token, here’s a screenshot of an action that utilizes the action to get a bearer token from Nintex.

 

 

The bearer token that’s produced is available to be parsed out in the TokenResponse variable.  Hopefully this, along with the nintex token api documentation (https://developer.nintex.com/docs/nc-api-docs/1e26b9d25afd4-applications), will help you figure out the format of whatever fields your particular service is needing. 

Reply