Yammer REST API - How can I fetch data from a different origin (CORS)?

New Contributor

I have created a Yammer app in "My Apps" and have set my Javascript Origin to my local development URL:

 

http://localhost:3000

 

In my React app, I am trying to use the Fetch API to get some data. For example:

 

 

const url = 'https://www. yammer.com/api/v1/messages/following.json';

const options = {
  method: 'GET',
  mode: 'cors',
  headers: {
    'Authorization': `Bearer ${process.env.REACT_APP_YAMMER_ACCESS_TOKEN}`,
  }
};

fetch(url, options).then(function(response) {
  console.log(response);
  return response.json();
}).then(function(json) {
  console.log(json);
});

 

 

I get a CORS error:

Access to fetch at 'https://www.yammer.com/api/v1/messages/following.json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

 

I have my Javascript Origin set in the Yammer dashboard and I have the mode set to CORS in my fetch request. What am I missing?

1 Reply

@mikelynch I got it working with a different URL:

 

const url = 'https://api. yammer.com/api/v1/messages.json';

 

I haven't seen this documented anywhere but I saw someone reference it here on a Stack Overflow post.