Getting started with testing API using Postman?

api
postman
authorization

#1

I’m new to web development and handling API’s and want to test it out and see the responses using Postman. Any ideas how the setup is like? I tried inputting the API’s provided, but been getting errors saying that the request is not authorized. Any suggestions would be appreciated. Thanks!


#2

Hi @Eunica_Lazatin, both awesome and crazy exciting that you’re learning more web dev stuff with our API.

I’ve never used Postman, but I just installed it and was able to make a simple request to Asana. Based on the error you’re getting, it looks like Asana isn’t getting the correct authorization to process your request.

Here is what I did to set up authorization for my request, hopefully it works for you too:

  1. Create new Request in Postman
  2. Under the Authorization tab, set the TYPE as Bearer Token
  3. Input an Asana Personal Access Token in the Token field. A Personal Access Token is something you can generate from Asana using the Apps tab in your Profile Settings. It will be a mix of numbers and letters that looks like a more serious version of this: 0/0a0a0a0a0a0a0a0a0a0a0a0
  4. The url I like to use for first time requests (and to start getting the lay of the land) is https://app.asana.com/api/1.0/users/me
  5. Click Preview Request
  6. Click Send, and you should get back some information about your Asana account :raised_hands:

Totally feel free to let us know if you have any other questions.


#3

Hi Daniel,

Thanks for the response and it works on postman! I actually have another question-- I am trying to make an ajax call and I am getting a 401 unauthorized error. I’ trying to GET one task from my asana homepage and I have it setup to where I have my ajax call then w/in that:

Authorization: {
Bearer : “Access Token”
},


#4

Asana will expect the “Authroization” header here to be a string rather than an object with a Bearer key.

The JSON should look something like this:

"Authorization": "Bearer 0/0a0a0a0a0a0a0a0a0a0a0a0"

(Where the odd looking number is your Personal Access Token).

If it helps, here is how I’d set up a basic Asana ajax call in full (I’ll use fetch(), but you could easily swap it out for jQuery’s ajax() or for whichever ajax library you prefer):

const fetchTask = (personalAccessToken, taskID) => {

   const response = await fetch(
      `https://app.asana.com/api/1.0/tasks/${taskID}`,
      {
         headers: {
            Authorization: `Bearer ${personalAccessToken}`
         }
      }
   )
   
   return response.json()
}

Hope that helps!