# CreateCustomer issue

**URL:** https://community.particle.io/t/createcustomer-issue/64137
**Category:** Cloud
**Created:** [March 6, 2023, 8:42pm UTC](https://community.particle.io/t/createcustomer-issue/64137 "2023-03-06T20:42:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Reindeer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/reindeer/32/27629_2.png) [@Reindeer](https://community.particle.io/u/Reindeer)
#### Post date: [March 6, 2023, 8:42pm UTC](https://community.particle.io/t/createcustomer-issue/64137/1 "2023-03-06T20:42:14Z")

</div>

I am trying to create a customer from a java script that I think matches the SDK’s required API, but get _Error: HTTP error 400 from [https://api.particle.io/v1/products/xxxxx/customers](https://api.particle.io/v1/products/xxxxx/customers) - Permission denied_.  
Note that I created a product and then created an oauth client related to that product. This client id and secret is what I use when calling particle.createCustomer.

```auto
function createCustomer(){
            let customerEmail = $('#customerEMail').val();
            let customerPassword = $('#customerPassWord').val();
            $('#statusSpan').text('Send create customer request.');
            particle.createCustomer({ product: 'xxxxx', client_id: 'yyyyy', 
                                      client_secret: 'zzzzz',
                                      email: customerEmail, password: customerPassword}).then(
                function (data) {
                    $('#statusSpan').text('Customer created.');
                },
                function (err) {
                    $('#statusSpan').text('Error creating customer:' + err);
                }
            );
        }

```

Your advice will be appreciated.

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [March 6, 2023, 9:20pm UTC](https://community.particle.io/t/createcustomer-issue/64137/2 "2023-03-06T21:20:29Z")

</div>

The particle-api-js doesn’t appear to take the `client_id` and `client_secret` as parameters to `createCustomer`.

It appears that you need to pass the `clientId` and `clientSecret` as an object passed to the `Particle` class constructor when you calls `new Particle()` instead.

---

<div class="post-metadata">

### Author: ![Reindeer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/reindeer/32/27629_2.png) [@Reindeer](https://community.particle.io/u/Reindeer)
#### Post date: [March 8, 2023, 5:34pm UTC](https://community.particle.io/t/createcustomer-issue/64137/3 "2023-03-08T17:34:56Z")

</div>

Thanks @rickkas7 for your response.  
I tried the following:

- Added the client id and secret to the Particle constructor:

```auto
var particle = new Particle({client_id:'xxxxxx', client_secret:'yyyyyy'});

```

- changed the function call to properly match the API:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/c/e/ce1fff4c6d6af8a04133ab0e43c789d2aae36d4b.png)

```auto
function createCustomer(){
            let customerEmail = $('#customerEMail').val();
            let customerPassword = $('#customerPassWord').val();
            $('#statusSpan').text('Send create customer request.');
            particle.createCustomer({email: customerEmail, password: customerPassword, product: productId, grant_type: 'password'}).then(
                function (data) {
                    $('#statusSpan').text('Customer created.');
                },
                function (err) {
                    $('#statusSpan').text('Error creating customer:' + err);
                }
            );
        }

```

Unfortunately I still get:

> HTTP error 400 from [https://api.particle.io/v1/products/zzzzzz/customers](https://api.particle.io/v1/products/zzzzzz/customers) - Permission denied

**However, the following does work (rejoicing!)**, which is probably a solution, but does not explain (to me at least) why the Particle JS API call does not work.

```auto
function createCustomer(){
            let customerEmail = $('#customerEMail').val();
            let customerPassword = $('#customerPassWord').val();
            $('#statusSpan').text('Send create customer request.');
            $.ajax({
                data: {
                    'client_id': particle.client_id,
                    'client_secret': particle.client_secret,
                    'grant_type' : 'password',
                    'email': customerEmail,
                    'password': customerPassword,
                },
                error: function (error) {
                    $('#statusSpan').text('error:'+JSON.stringify(error));
                },
                method: 'POST',
                success: function (data) {
                    //ajaxResponse = JSON.parse(data).access_token;
                    $('#statusSpan').text('Customer created with access token:' + JSON.stringify(data));
                },
                url: 'https://api.particle.io/v1/products/' + productId +'/customers',
            });
        }

```

Your insight will be much appreciated.

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [March 8, 2023, 5:40pm UTC](https://community.particle.io/t/createcustomer-issue/64137/4 "2023-03-08T17:40:10Z")

</div>

I would do it the way you did it, using ajax, if that’s working.

It looks like particle-api-js uses a different grant\_type, which does seem wrong to me.

> <https://github.com/particle-iot/particle-api-js/blob/master/src/Particle.js#L188>

---

<div class="post-metadata">

### Author: ![Reindeer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/reindeer/32/27629_2.png) [@Reindeer](https://community.particle.io/u/Reindeer)
#### Post date: [March 8, 2023, 5:41pm UTC](https://community.particle.io/t/createcustomer-issue/64137/5 "2023-03-08T17:41:45Z")

</div>

Thanks for the prompt feedback!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)
#### Post date: [April 8, 2023, 3:42am UTC](https://community.particle.io/t/createcustomer-issue/64137/6 "2023-04-08T03:42:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
