BetterCloud Custom Integration / Pre-Request Script Authorization Question


Howdy, i'm new to BC custom integrations. I'm trying to get an oauth integration setup. I've gotten the pre-auth script built out but am not sure how to get the authorization code that is recived out of the script to be used in an action. Any help would be appreciated.


30 replies

Userlevel 5
Badge +2

Hey @ishboo3002@gmail.com 👋 welcome .... this is probably better for the #bettercloud-api channel but we can help you out here (cc: @jb.lovell)


Open Thread in Slack

I can re-post there if its easier.


Open Thread in Slack
Userlevel 5
Badge +2

No worries, I'll cross post the thread later on


Open Thread in Slack
Userlevel 5
Badge +2

so in your pre-request script after you've gotten the API key, you ultimately have to return request data back which is used to execute the action you're creating


Open Thread in Slack
Userlevel 5
Badge +2

so in the script, I'd set the request headers and include the authorization code


Open Thread in Slack
Userlevel 5
Badge +2

I'll see if I can find an example. @jb.lovell@justin.little@catherine.achukwu maybe be able to help out as well


Open Thread in Slack

that'd be great i tried setting it as the request.body and returning the body but not sure how to assign that to a secret to be used in the header for an action.


Open Thread in Slack
Userlevel 2
Badge +2

Looking for an example real quick


Open Thread in Slack

if this helps


Open Thread in Slack
Userlevel 2
Badge +2

https://youtu.be/AZeaUdBcqk4


Open Thread in Slack
Userlevel 2
Badge +2

@ishboo3002@gmail.com Check out this video at about 4:00. Really at about 4:40, you'll see what you need.


Open Thread in Slack
Userlevel 2
Badge +2

From your script above, I'm guessing you'll need to grab the token out of there and callback to the webhook with it in the headers. In the video we're manipulating the webhook URL, but the same applies to the webhook headers.


Open Thread in Slack

so im not using a webhook, im trying to get an oauth token to use in actions


Open Thread in Slack

its not really data transform but a an action pre-request


Open Thread in Slack
Userlevel 2
Badge +2

Ahh, so every action in workflows is a webhook. So you'll have to attach that script to a webhook for it to show up in your workflows


Open Thread in Slack
Userlevel 2
Badge +2

What you could do is, create a webhook that is making the same request you're making in the script. That'll return a token as a dynamic field so you can use it in later actions, if that's what you're looking for.


Open Thread in Slack

ah so basically have an action for oauth


Open Thread in Slack
Userlevel 2
Badge +2

Yep, webhook to get the token and webhook to take the action, taking the token in as a dynamic field.


Open Thread in Slack

and pass in the url from the action


Open Thread in Slack

got it, i'll give that a go.


Open Thread in Slack

appreciate the help!


Open Thread in Slack
Userlevel 2
Badge +2

Really, best practice is to use an action pre-request script to get the token, then set that in headers for the attached webhook. Essentially the same thing you see in that video, just change out the getUserId function for a getToken function.
This will likely give you the best results. You can re-use that script for any other actions this was as well.


Open Thread in Slack

ooh that makes even more sense


Open Thread in Slack

which is what i was trying to do, but didn't realize that the action was a webhook


Open Thread in Slack
Userlevel 2
Badge +2

No problem. Remember, we also have office hours too that we can work through this stuff with you if you're interested. https://calendly.com/eag-consult/custom-integrations-office-hours


Open Thread in Slack

Reply