- In this video, I'm gonna show you how you can pull data
from an API with the help of Postman app.
All the more coming up right after this.
Hi there, and welcome to another video of measureshool.com
where we teach you the data-driven way of digital marketing.
My name is Julian, and on this channel,
we do marketing tech reviews, tutorials,
and give you tips on how to become
a more technical marketer, just like this one.
So, if you haven't yet, consider subscribing.
Now data is everywhere, but how do you get to it?
Well, most of the times, you will go through an API.
Now, APIs have been used by developers quite often
to pull data into the app or the website, display it,
manipulate it, or change it around
in the third party system.
But, we as marketers can actually also use that data,
if you just know how to get to it.
Now, before you start building an app, try to retrieve
that data and mesh it around and maybe
send it back into your analytics system,
why not try to get the request right first?
And this is where Postman app comes in.
Now, with Postman app, you can actually test APIs,
and without coding, can send in a request
with the right parameters and see what data you get back.
Highly useful for us marketers because we can then
instruct our developer to pull the right data
or help us to build an app to actually take that data
and send it onto a marketing script
or a marketing tool like Google analytics.
So, today I want to show you how you can use
Postman app to retrieve data from an API,
send your first request, and also manipulate data
in a third party system.
Now, we got lots to cover, so let's dive in.
Alright, today our journey starts at getpostman.com
where you can download the Postman app,
previously it was also available just to download it
as a Chrome app, but that's been depreciated,
but here you can download it for your Mac,
your Windows, or Linux machine.
And once you install it, it should look something like this.
Now, the tool in its basis is a free tool,
which we can use as marketers just to see APIs,
but if you want to take advantage
of more of the advanced features,
there's also a pro version and enterprise version.
Now, this tool is most often used to develop and test APIs.
I actually use it most often before I start our building,
for example, my favorite app scripts here,
or a function within JavaScript.
I want to actually know what data do I need to send
into an API to get the right response.
And Postman lets me do all of this without having
to code too much and get caught up in any kind of syntax
that I might do wrong within Fscript or JavaScript or PHP
Rugan rails or any other language you use
to grab information from APIs.
Now, you might have seen something similar.
It is actually like the Query Explorer
for the Google Analytics Core Reporting API.
You login here, then you can try out the API,
mix and match certain metrics for example,
and pull that data directly from the API,
get the output right here.
Now, if you actually wanted to integrate this
into your app and have the right parameters
that you send into the API to get a response,
you would probably test this with something
like Postman beforehand.
So let's get started with our first request.
Here is an API that gives me some Chuck Norris quotes,
and it specifies that I just simply simply need
to send a get response to this endpoint,
this URL to get my random quote.
So, let's try this out, let's copy this URL,
go over to Postman, and put in our URL right here,
and then we have our different methods of sending that data.
We want to go with the get response.
Now, we can send this off, and we get a response,
and this is actually a Jason response,
so this is JavaScript object notation,
and this is the structured way that we can get
the data back, and we see here the value
of this object is actually our quote that we wanted to get.
So, pretty easy.
In this sense, Postman is almost like a browser.
You put in your URL, send it off and get a response.
Now, if you do any kind of mistake, so let's add something
to the end here and send it, we see that the status
is a 500 internal error.
We get a message from the API back.
That's not always the case, but it helps us debug
and maybe find something that we did wrong.
Now, this is a very, very easy API, but we can just send
in our URL and get a response back.
In most cases, it's it a bit advanced that that.
Let's go to another example, so here we have
the weather API, the OpenWeatherMap,
and we can actually get a current weather status for a city.
Now, what do we have to do?
We have to send in as a query string
here in our URL the actual location.
So, let's try this out.
Let's take our API call here and put it into place.
Now we have a query string, this is key of Q
and the value of the city name, in our case Berlin.
By the way, if you don't want to type that out
in the URL itself, you could also at any time click
this Params here at the end, and type in the right key.
and the value will be added automatically to your request.
Then we can send this off and we get
a negative response here of 401,
saying that this is an invalid API key.
Apparently, we need an API key to get the data
from this API, and this is actually something that is
required quite often with not as open APIs
as the Chuck Norris API.
So, we actually need to sign up
to get our API key right here, so let's copy that,
and we actually need to send it in somehow,
so let's see how to do that.
We can look up this in our documentation here,
and we just need to attach another query parameter,
which is the app ID with our API key, so let's do that.
Let's go back and put in app ID, and then here our API key.
Send this all off, and this time we get a response
that right now in Berlin, there are clouds
and description, broken clouds.
So, quite interesting to see the response data
and what data we can actually get out and maybe test that
and send it onto a tracking script
that sends the data over to Google analytics,
so we would have the data in there, what weather it was
at the location of our user, who just visited
our website or bought our product.
So far, so good, but we can not only get data from API,
but also affect a change in the application itself,
and this is done through other requests such
as the post request, so let's take a look
at an example of that.
Here we are in our MailChimp account,
and MailChimp also has an API, so if we scroll down,
we can see can see here the API docs.
I actually need to log in first into my demo account here,
and we can look into the API references
and see what we would need to make this actually happen.
First of all, this would be our URL,
so I'm gonna copy that over.
We actually need to make sure that we have
our data center changed here,
in our case, that would be US8.
And then we need to authorize with our app ID probably.
The authentication this time happens through HTTP basic,
so let's go over to our MailChimp account and look
into our account options here under extras,
we can get our API key, and here we have our API key
that we copy and do some special authorizations,
so the basic authorization and the user name
in the case of MailChimp can be anything.
I'm just gonna put "anything" and the password, our API key.
That is something we want to request with our data,
and now it's been added to the header of our request
and we should be able to send over request already.
Here, we get our account information back.
Now we can look into the developer reference
and see how we can, for example, add a user to a list,
so let's go over to list here, and let's say we wanted
to create a new member of that list.
What we would need to have is the list ID,
and then we can create any member.
What do we have to send in?
The email address, the status at least.
Okay, let's do that.
First of all, let's find out, what is our list ID?
Now, we could look it up in the interface,
but we could also just put in lists right here,
and send this request over in order
to see what kind of lists we have.
We actually have one list and the Id is this ID right here,
so we will add that to our request as well,
and then we can go into our members.
Let's send this off and we get all the test users
that I've entered in the system right here.
Now in order to create our member, we actually need
to send over a post request, so let's change our method
here to post, and how do we need to send that data?
And this is always different for different APIs.
We actually need to write a body request,
so our request need to be in the body, in which kind
of form is also listed in the API requirements,
which is a neat Jason format,
so we can now add it to body right here.
There are different forms and we need
to choose the Jason format, so I'll go with raw here
and change around the Jason format to this,
and then I'll wrap a JavaScript object in the Jason format,
so with the key value pair surrounded by double quotes,
and what do I need?
I need an email address, comma, and then we need the status.
Alright, so what do we need to fill out here?
The email address is obviously a string,
and then the status would be also a string.
The possible values would be subscribe,
unsubscribe, clean, and so on.
So, we'll go with subscribe.
So, let's fill that out.
And that should be it.
Let's send that data over.
And we get a response back that our user was edit.
He should be now in the system,
so let's see if this is actually the case.
Let's go back into our list, and click on here,
and look through our requests, and here we go,
our new user was added to the system.
So, you can not only look for data or get a response
from an API, but also post that data into the system.
Now, there's much more that we can cover right now
in this video, different authorizations for example,
the OAuth method, which is used
quite often for authorization.
There are different ways of sending data in,
by the header or the body.
There are different methods of sending a request as well,
and I hope this gave you little bit of an idea on
how you can use Postman to get a response back,
to test APIs, see how they function, what parameters
you need to send in, in order to get
a correct response back, and see how they behave
in certain circumstances.
Alright, so there you have it.
This is how you can retrieve and send data
into an API and get a response back.
Now, there's much more to APIs, but also to Postman,
so we put together a little mini course
that you can check out at techmarketer.io/postman
where we actually go more into detail
on different requests you can send in, different,
more examples on APIs and much more,
so check that out at techmarketer.it/postman.
Now, if you like this video, then don't forget
to give us a thumbs up, and also if you haven't yet,
consider subscribing right over there,
because we will bring you new videos
on this channel every week.
My name is Julian, til next time.