51黑料不打烊

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鈥檒l be covering how to make our first access token request, get the response back and then save it into a variable. There鈥檚 a prerequisite before starting, please follow the link below if you haven鈥檛 done so already. Make sure that you鈥檝e created an API only user and it鈥檚 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鈥檛 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鈥檙e going to be setting up our environment as you can see there鈥檚 no environment created so we see on the environment quick look on the right we鈥檙e going to click on that and then click environment. There鈥檚 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鈥檙e 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鈥檙e going to call that base underscore URL the type of variable this is is a default type there鈥檚 nothing sensitive there so that鈥檚 perfect. The second one we鈥檙e going to be creating it鈥檚 the munchkin code this is the variable that鈥檚 going to actually house the munchkin code so since this is a sensitive data we鈥檙e 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鈥檙e 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鈥檚 why there is a required to set up that service so this is a sensitive data we鈥檙e going to set it to secret and then we鈥檙e 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鈥檙e going to set a default there is a time over to expire so by the time you guys get this it鈥檚 already expired so it鈥檚 pretty so it鈥檚 pretty safe for us to keep this as default we鈥檙e not going to be using initial value at this point only current value just because that initial value is used for if you鈥檙e 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鈥檙e 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鈥檙e going to set up our base URL and base URL is HTTPS colon forward slash forward slash and then we鈥檙e 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鈥檙e 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鈥檙e going to our Marchetto admin we鈥檙e login click on the admin on the top and then there鈥檚 something called munchkin on the left click on that and you鈥檒l 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鈥檛 show it will be encrypted it won鈥檛 show the actual data so we can safely just paste it and you won鈥檛 see it there is a I that鈥檚 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鈥檚 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鈥檛 have this please go ahead and set that up so we鈥檙e gonna go ahead and copy and paste that value in here and then we鈥檙e gonna grab the client secret also set as its secret type so it鈥檚 encrypted there that I won鈥檛 show on the screen and we just paste it in there now the access token this is what we鈥檙e 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鈥檙e gonna add double curly brackets and I鈥檓 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鈥檙e gonna keep it as default but you can go ahead and put a secret if this wasn鈥檛 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鈥檚 fairly safe so now we鈥檙e 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鈥檚 a red dot up there that means there is unsaved work so let鈥檚 go ahead and save our work so we don鈥檛 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鈥檙e 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鈥檚 give this collection a name you can name it whatever you like but in this case for the purpose of this video I鈥檓 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鈥檚 click on the authorization so pair the documentation we have to set up the bear type authentication so we鈥檙e gonna select the bear type from here not bear token the one right underneath it I apologize one more there we go now it鈥檚 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鈥檚 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鈥檙e 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鈥檛 be good so let鈥檚 let鈥檚 just continue on maybe you know we鈥檒l get to it later on so let鈥檚 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鈥檙e gonna keep it as get and put in our URL but before so let鈥檚 go ahead and call this request what is this request for what is the purpose of this it called request I鈥檓 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鈥檓 just calling access underscore token and then color authorization right because that鈥檚 really what we鈥檙e doing here we鈥檙e getting that access token and that鈥檚 the variable name we鈥檙e using so we鈥檙e gonna keep it as a vet as I get API pull API type again we鈥檙e 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鈥檙e doing is really just taking that the URL string from the documentation adding our variables to it you鈥檝e 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鈥檙e sending out the client credentials just because of the that鈥檚 what it鈥檚 instructing us to do in the docs so we鈥檙e seeing so let鈥檚 go ahead and make a call and we鈥檙e seeing a lot of error messages and we鈥檙e basically seeing that a base URL is not found so there鈥檚 something wrong with that string but we move over these red environments it鈥檚 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鈥檛 have access to anything outside of that so on the top right you see there鈥檚 no environment selected let鈥檚 go ahead and select the environment we created and you鈥檒l 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鈥檚 that encrypted client ID and encrypted client seeker so it鈥檚 actually pulling the data now from the variables it is working as this shirt so now we鈥檙e getting somewhere let鈥檚 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鈥檚 great now let鈥檚 see how the access token it鈥檚 not here right so when we look at access token variable that data from absolutely should be here and it鈥檚 not so it鈥檚 not fetching it so if you鈥檙e using this variable elsewhere to get this it鈥檚 not going to work because it鈥檚 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鈥檚 access token that we鈥檙e actually requesting data from that is a request there that鈥檚 the data that we want to populate with our variable of access token so now that we have that JavaScript in place let鈥檚 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鈥檚 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