ÃÛ¶¹ÊÓƵ

API Help - How to set the Access token in a variable

Learn how to set up the Postman application and leverage variables to save data into the variable for reusability purposes. You will also learn how to make your first Marketo Engage REST API call to get the access token.

PREREQUISITES
Before starting this video, create an API Only username with an AOI role and create a Launchpad service. Follow the steps in the articles below:

References used in this video:

  • Marketo auth endpoint: {{{}base_url{}}}/identity/oauth/token?grant_type=client_credentials&client_id={{{}client_id{}}}&client_secret={{{}client_secret{}}}

  • JS script to grab acccess_token from the response body (places under the Scripts: tab):

var jsonData = pm.response.json();
pm.environment.set("access_token", jsonData.access_token);

video poster

Transcript
Hello everyone, thank you for watching our Marketo engage API how to video. In this video we’ll be covering how to make our first access token request, get the response back and then save it into a variable. There’s a prerequisite before starting, please follow the link below if you haven’t done so already. Make sure that you’ve created an API only user and it’s signed it to an API role as well too and then use that username to also the API username to also create a service under launchpad. That is required before we can continue if you haven’t done so please pause the video and follow those steps and then continue. For the rest of us we can continue on setting up our postman and configuring it to make our first API call. So first we’re going to be setting up our environment as you can see there’s no environment created so we see on the environment quick look on the right we’re going to click on that and then click environment. There’s two selected levels here environment and global so you can essentially set up the variables on each one of those levels for the sake of this video we’re just going to stick to the environment level. Now once we say add the environment it wants us to give it a name so go ahead and give it a name that you like that you want to call your environment. In my case here I will go ahead and call it my Marketo videos that is the name of my environment and then from this point on we can go on select set up these variables set the type and then add in the values. So the first variable we want to create is the base URL this is the URL that houses our entire domain then the entire domain name and the URL string for our API call so we’re going to call that base underscore URL the type of variable this is is a default type there’s nothing sensitive there so that’s perfect. The second one we’re going to be creating it’s the munchkin code this is the variable that’s going to actually house the munchkin code so since this is a sensitive data we’re going to set that to secret and the next one we will be creating here is the client underscore ID and this is also a sensitive data we’re going to set it to secret and the and both the client ID and the next one which is a client underscore secret these are both coming from the launch path the values come from the launch path that’s why there is a required to set up that service so this is a sensitive data we’re going to set it to secret and then we’re going to have our access token here this is generally this is where we are going to house the response API response that we get back through the body and then save that in here generally I would want to set this a secret but for the sake of this video we’re going to set a default there is a time over to expire so by the time you guys get this it’s already expired so it’s pretty so it’s pretty safe for us to keep this as default we’re not going to be using initial value at this point only current value just because that initial value is used for if you’re using different more than one scope so you can kind of and if it varies being created on a different scope you can see that value that was set up being kind of compare so we’re going to be focusing on the current value for the sake of this video but just know that there is another level into in this window you know and setting up variables when needed so there are multiple scopes here so we’re going to set up our base URL and base URL is HTTPS colon forward slash forward slash and then we’re going to grab that monochrome code variable we created below so instead of just adding a monochrome code which is a bunch of numbers and and and alphabets at the MKTO rest.com we actually going to call out the variable and we do that by adding two curly bracket and then adding the variable name which is monochrome in this case and then we add in dot MKTO rest.com a little misspelling there we’re gonna get that fixed there we go so double curly bracket open munchkin double curly bracket close MKTO rest.com and now we can go ahead and grab that munchkin code from our admin and to do so we’re going to our Marchetto admin we’re login click on the admin on the top and then there’s something called munchkin on the left click on that and you’ll see it one of the first I believe the first row that is showing your munchkin code so please go ahead and grab that and I will just copy and paste it in here so now since the tab is set to secret it won’t show it will be encrypted it won’t show the actual data so we can safely just paste it and you won’t see it there is a I that’s crossed out through to the right that you can click on if you do want to see it as a toggle but for the save of this video we keep it encrypted client ID comes from to from from a munchkin code admin two steps down it’s called the launchpad click on that please and then pick the service name that you created before and say view details on the right to it and then you see a pop-up screen with both client ID and client secret and also the API user the third option for you to pick from so all we want to do now from this is just copy and paste the client ID copy it and then paste it into our current value here in postman so again this is a prerequisite that was required to have set up before starting this video if you don’t have this please go ahead and set that up so we’re gonna go ahead and copy and paste that value in here and then we’re gonna grab the client secret also set as its secret type so it’s encrypted there that I won’t show on the screen and we just paste it in there now the access token this is what we’re gonna actually get the access token from the response body and then save it into the variable so all we want to do here is really just show us the data right what does this variable what data is saved into this variable so to do that just as we did above we’re gonna add double curly brackets and I’m gonna add in the variable name and then close out the accrual bracket typically I would want this to the secret since it is sensitive data but for the purpose of this video I want us to see the data actually populating so we’re gonna keep it as default but you can go ahead and put a secret if this wasn’t for this video I will send it a secret as well but there is a time here today so it will expire eventually by the time you guys see this is already expired so it’s fairly safe so now we’re gonna go and add that variable in there which is a double curly bracket access token and then close it out with double curly bracket so there’s a red dot up there that means there is unsaved work so let’s go ahead and save our work so we don’t lose anything and also so all this information can become active within the system there we go now we have our variable set up they’re good to go so now we can go on and create a collection go ahead and click on the collection tab on the left and then create the collection button now let’s give this collection a name you can name it whatever you like but in this case for the purpose of this video I’m just gonna call this my Marchetto API calls there we go now we have that set up we can add a request but before so let’s click on the authorization so pair the documentation we have to set up the bear type authentication so we’re gonna select the bear type from here not bear token the one right underneath it I apologize one more there we go now it’s asking for a token now this is just saying what is the token right so we can either pass it feed it the hard data and just hardcover in there or we can use a variable since we already have this variable for the token safe on the access underscore token variable let’s go ahead and just assign that so we have everything uniform and all the data comes streaming from its it really has a one point of control so we’re gonna add it in here double the double curly bracket open access token and then close it out and we see get an error message unresolved variable all right well that can’t be good so let’s let’s just continue on maybe you know we’ll get to it later on so let’s just continue with adding our request click the blue add request button to your left and then we can start actually doing the API work right so we can say what kind of API type if you want is it a post is it get is it something else in this case we’re gonna keep it as get and put in our URL but before so let’s go ahead and call this request what is this request for what is the purpose of this it called request I’m gonna call it for a second ratio and also sake off just keeping things easy and and and and easy to just navigate through it and the good the overview I’m just calling access underscore token and then color authorization right because that’s really what we’re doing here we’re getting that access token and that’s the variable name we’re using so we’re gonna keep it as a vet as I get API pull API type again we’re gonna use the base URL and then using the endpoint right there that you know you also can find within the authorization documentation so all we’re doing is really just taking that the URL string from the documentation adding our variables to it you’ve already seen the client secret and a client IDs and the base URLs now those red the only I should say for that the only thing we added here was the grand type which we’re sending out the client credentials just because of the that’s what it’s instructing us to do in the docs so we’re seeing so let’s go ahead and make a call and we’re seeing a lot of error messages and we’re basically seeing that a base URL is not found so there’s something wrong with that string but we move over these red environments it’s the all showing is an arrow that unresolved variable error we saw earlier now this is it wants us to add a new variable but we just added all those variables we spend so much time on it why not just reuse that so what can be the reason right if you guys remember I said there are multiple scopes of sending the variables there is an environment and a global scope so to keep things within an environment we just say that on environment level so the system doesn’t have access to anything outside of that so on the top right you see there’s no environment selected let’s go ahead and select the environment we created and you’ll see that all these base URLs are now responding with the right data this is the our our munchkin MKT arrest string you put in there’s that encrypted client ID and encrypted client seeker so it’s actually pulling the data now from the variables it is working as this shirt so now we’re getting somewhere let’s go ahead and set that request again and there we have it there is an access token that we were looking for there is a there is a token type the expiration and everything is there user even is there so that’s great now let’s see how the access token it’s not here right so when we look at access token variable that data from absolutely should be here and it’s not so it’s not fetching it so if you’re using this variable elsewhere to get this it’s not going to work because it’s not repopulating the variable with that data so we need that data from access token from the right of it in there and to do so we actually need to interject a little bit of a JavaScript so if you guys want a script tab on the top and then just copy and paste the script that I also have supplied the bottom all this does is really just looks at the postmaster response body and it grabs the access token data so the value associated with it and assign it to our access token variable and you can see below there’s access token that we’re actually requesting data from that is a request there that’s the data that we want to populate with our variable of access token so now that we have that JavaScript in place let’s go ahead and save and then run this again no big changes here everything looks the same but then when we actually take a look inside our variable view we see that that data is now being populated so now we can use that variable elsewhere and the data comes with it that’s really all the ways to it I hope this was helpful for you please let us know if you have any questions thanks for watching
recommendation-more-help
65ee5e5e-b058-48c8-aa13-bacc3d5848ce