Dear all !
I want to fetch customers from Shopify store to ionic service,
I sent a get request to Shopify using postman, there is not problem, I chose authorization type: Basic Auth
My question is how to format this request in ionic?
Please help me
postman screenshot
What does it have to do with Ionic?
Ionic doesn’t provide you some “Special” http service or something.
dear @ekhmoi thanks for replying
I have built a shopping cart, in this app what customers can do; register them self, add product to cart and send order.
in back-end I need to do the following:
- send a get request to shopify to fetch products
- send a get request to shopify to fetch collections
- send a get request to shopify to fetch customers
- send a post request to shopify to store orders
- send a post request to shopify to store customers
my problem:
in order to send request to shopify and if you choose auth-type as “Basic Auth” you need to provide a username and a password,
I have created the required username and password in shopify store
I can send the above requests to shopify using postman but I don’t know how to do in ionic 3?
I understood your problem. However it has nothing to do with Ionic. So asking the question here is not appropriate.
Anyways here is what you need to do.
First encode your username and password:
const encoded = btoa(username + ":" + password);
Then add this to your request headers:
import { Headers } from '@angular/http';
...
const headers = new Headers();
headers.append('Authorization', `Basic ${encoded}`);
const subscription = this.http.post(url, body, { headers });
Note: As you haven’t provided any code this might not exactly work for you with copy paste (you might be using HttpClient which uses HttpHeaders instead).
Thanks @ekhmoi for quick response
I applied the code but I’m getting unauthorized access
please help me if I’m missing anything.
actually I’m new in ionic
thank you
cod in home.ts file
console error
If I add access-control-allow-origin to header
then I get this error in the console
You might want to burn that username/password combo and redact it in the future.
Dear @rapropos I want to send the username and password to server to get token.
Dear @ekhmoi, do I need to send body with a post request? I’m sending the username and password in header, in this case I can send a get request right?
If my request is incorrect please tell me how to make a correct request ?
thank you