nouvak / magento2-rest-client

MIT License
14 stars 11 forks source link

angularJS 2 implemention #2

Open refaelgold opened 7 years ago

refaelgold commented 7 years ago

Hey , i'm tries for weeks to create a token inside angularJS 2 but i get only 400 or 401 .Can you give me some help how to use your module in AngularJS 2? Thanks

nouvak commented 7 years ago

Hi! Unfortunately, I never used the library with AngularJS 2. Can you have a look at magento2 logs to get more details why magento rejects your requests?

Greetings Marko

refaelgold commented 7 years ago

i try to send the Authorization header but i think i can do it only with OAuth 1a . when i try to get the token from POSTMAN i can get it but when i try to put with with header only i get 400.

Do i must use OAuth 1a to enable the access for code? A lot of programmers getting stack with the token part when the try to get full access

99percent6 commented 6 years ago

Hi, guys! I have the same problem but i'm using it with node.js. Maybe you have some solutions?

nouvak commented 6 years ago

Hi Vladimir!

Unfortunately, I'm not actively developing that REST client. Therefore I really cannot tell what the issue could be...

On Thu, Mar 15, 2018 at 9:58 AM, Vladimir notifications@github.com wrote:

Hi, guys! I have the same problem but i'm using it with node.js. Maybe you have some solutions?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nouvak/magento2-rest-client/issues/2#issuecomment-373305169, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkihRBUxIOfKuqOt9zjYZu1mLfLfEOZks5tei0YgaJpZM4Nb_Yq .

-- Marko Novak Twitter: @MarkoNouvak LinkedIn: https://www.linkedin.com/profile/view?id=15369898 blogger.com: http://novakmarko.blogspot.com/

99percent6 commented 6 years ago

it's a pity, but in any case, thanks, Marko.

HamiltonWang commented 6 years ago

mine is working fine Can you get your token? if you can correctly obtain your token, it means you set up your Magento oAuth correctly. If not, the problem is most likely in your Magento oAuth setup.

Getting token

var request = require("request");

var options = { method: 'POST',
  url: 'http://your_url/rest/V1/integration/customer/token',
  headers: 
   { 'Postman-Token': 'adee7740-8a2d-40f2-b239-b2b16d020843',
     'Cache-Control': 'no-cache',
     'Content-Type': 'application/json' },
  body: { username: 'xxxxx@xxxxxx', password: 'xxxxxx' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Request for country sample

var request = require("request");

var options = { method: 'GET',
  url: 'http://your_url/rest/default/V1/directory/countries',
  headers: 
   { 'Postman-Token': '08769517-b40b-45dc-bffa-d1e532129c04',
     'Cache-Control': 'no-cache',
     'Content-Type': 'application/json' },
  body: { username: 'xxxxxxxx', password: 'xxxxxxxxx' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});