Getting started with testing API using Postman?

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!

1 Like

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.

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”
},

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!

Hi,
I am new in asana.
Asana has 122 API request.
How can i get demo token and all types of {gid} for test in postman which i actually work for demo user.
In documentation give only {
gid} and what require. But not give how to get them in easy way.

Hi @Siddiquee and welcome to the forum!

Get yourself a Personal Access Token - it’s an easy way you can authenticate to your own Asana account without having to deal with OAuth. Here’s how:

One way to get project and task gids is to copy them from the browser address bar when you’re focused on a project or a task.

Other than that, you can get them in a building-block manner using Postman. For example, you can copy a project gid from your address bar, then use that gid with the GET /projects/{project_gid}/tasks endpoint to get a list of tasks in the project. Then you can grab the gid of one of the tasks in that list and use it for testing task-based API calls.

1 Like