# How to make an authenticated request to Shopify?

**URL:** <https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098>\
**Category:** ionic-v3\
**Created:** [July 1, 2018, 11:03am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098 "2018-07-01T11:03:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziaionic](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@ziaionic](https://forum.ionicframework.com/u/ziaionic)\
**Post date:** [July 1, 2018, 11:03am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/1 "2018-07-01T11:03:17Z")

</div>

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

 ![postman](https://global.discourse-cdn.com/ionicframework/original/3X/6/a/6a5fe491fbc372fdb485150275cae505e7ef80e0.PNG)

---

<div class="post-metadata">

**Author:** ![ekhmoi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ekhmoi/32/103413_2.png) [@ekhmoi](https://forum.ionicframework.com/u/ekhmoi)\
**Post date:** [July 1, 2018, 5:33pm UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/2 "2018-07-01T17:33:20Z")

</div>

What does it have to do with Ionic?  
Ionic doesn’t provide you some “Special” http service or something.

---

<div class="post-metadata">

**Author:** ![ziaionic](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@ziaionic](https://forum.ionicframework.com/u/ziaionic)\
**Post date:** [July 2, 2018, 6:18am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/3 "2018-07-02T06:18:03Z")

</div>

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:

1. send a get request to shopify to fetch products
2. send a get request to shopify to fetch collections
3. send a get request to shopify to fetch customers
4. send a post request to shopify to store orders
5. 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?

---

<div class="post-metadata">

**Author:** ![ekhmoi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ekhmoi/32/103413_2.png) [@ekhmoi](https://forum.ionicframework.com/u/ekhmoi)\
**Post date:** [July 2, 2018, 6:37am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/4 "2018-07-02T06:37:59Z")

</div>

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:

```auto
const encoded = btoa(username + ":" + password);

```

Then add this to your request headers:

```auto
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).

---

<div class="post-metadata">

**Author:** ![ziaionic](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@ziaionic](https://forum.ionicframework.com/u/ziaionic)\
**Post date:** [July 2, 2018, 10:23am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/5 "2018-07-02T10:23:35Z")

</div>

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  
 ![2](https://global.discourse-cdn.com/ionicframework/original/3X/e/4/e4bb86cf5ee80878a41bfc74f320d19b69053361.PNG)

console error

 ![1](https://global.discourse-cdn.com/ionicframework/original/3X/e/f/ef9c04faeb190c956a8bf37ff1453505f5a31edf.PNG)

If I add access-control-allow-origin to header  
 ![3](https://global.discourse-cdn.com/ionicframework/original/3X/1/6/16fac49659f1700feaab7a94f0f764de405b2c4e.PNG)

then I get this error in the console

 ![4](https://global.discourse-cdn.com/ionicframework/original/3X/6/a/6a312c4da19e66a97ebe32fe77620bb46e219c31.PNG)

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [July 2, 2018, 8:54pm UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/6 "2018-07-02T20:54:32Z")

</div>

You might want to burn that username/password combo and redact it in the future.

---

<div class="post-metadata">

**Author:** ![ziaionic](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@ziaionic](https://forum.ionicframework.com/u/ziaionic)\
**Post date:** [July 3, 2018, 3:38am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/7 "2018-07-03T03:38:56Z")

</div>

Dear @rapropos I want to send the username and password to server to get token.

---

<div class="post-metadata">

**Author:** ![ziaionic](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@ziaionic](https://forum.ionicframework.com/u/ziaionic)\
**Post date:** [July 3, 2018, 5:30am UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/8 "2018-07-03T05:30:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:30pm UTC](https://forum.ionicframework.com/t/how-to-make-an-authenticated-request-to-shopify/134098/9 "2021-07-19T21:30:38Z")

</div>

Closed on July 19, 2021, 9:30pm UTC


