# crm-backend

**URL:** <https://forum.wixstudio.com/t/crm-backend/15735>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 19, 2019, 5:44pm UTC](https://forum.wixstudio.com/t/crm-backend/15735 "2019-03-19T17:44:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![joceyricardo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/joceyricardo/32/9868_2.png) [@joceyricardo](https://forum.wixstudio.com/u/joceyricardo)\
**Post date:** [March 19, 2019, 5:44pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/1 "2019-03-19T17:44:47Z")

</div>

Hi i’m trying to create a contact from a form that i have created I’m using crm-backend, but I’m geeting the below error: " Error: server responded with 403 - {“message”:“permission\_denied, details: {"RequiredRole":"Anonymous User","GivenIds":"member → d5e81888-e7f1-4348-932d-dfdf44897d48"}”,“details”:{“givenids”:“member → d5e81888-e7f1-4348-932d-dfdf44897d48”,“requiredrole”:“Anonymous User”,“error”:“permission\_denied”,“category”:“api\_error”}}"

This is the code at the backend:

import wixCrm **from** ‘wix-crm-backend’;

export function myBackendFunction(firstName, lastName, emails, phones) {  
**return** wixCrm.createContact( {  
“firstName”: firstName,  
“lastName”: lastName,  
“emails”: [emails],  
“phones”: [phones]  
} )

}

This is the code at the frontend

export function buttonSubmit\_click(event) {  
//Add your code for this event here:  
**let** firstName = “Luis”  
**let** lastName = “Perez”  
**let** emails = “[ricardo@data.com](mailto:ricardo@data.com)”  
**let** phones = “254124256254”

```
myBackendFunction(firstName, lastName, emails, phones) 
.then( (contactId) => { 
    console.log(contactId) 
} ) 
. **catch** (err => console.log(err)) 

```

}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [March 19, 2019, 11:43pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/2 "2019-03-19T23:43:36Z")

</div>

First, make sure that your code is correct for your backend file and you haven’t added or left out any parts of the code:  
[https://www.wix.com/code/reference/wix-crm-backend.html](https://www.wix.com/code/reference/wix-crm-backend.html)

Second, in your page code you are going to need onReady and calls to import wix-crm backend and to import your backend function.

There are a few register options here which already have all the backend codes and page codes set up for them, maybe try using these as examples and change your code to suit your needs.  
[https://www.wix.com/code/reference/wix-users-backend.html#approveByToken](https://www.wix.com/code/reference/wix-users-backend.html#approveByToken)

---

<div class="post-metadata">

**Author:** ![appsvorstel](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/appsvorstel/32/11607_2.png) [@appsvorstel](https://forum.wixstudio.com/u/appsvorstel)\
**Post date:** [July 19, 2019, 1:15pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/3 "2019-07-19T13:15:47Z")

</div>

Was this solved?

---

<div class="post-metadata">

**Author:** ![mennyg19](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mennyg19/32/9941_2.png) [@mennyg19](https://forum.wixstudio.com/u/mennyg19)\
**Post date:** [September 5, 2019, 10:44am UTC](https://forum.wixstudio.com/t/crm-backend/15735/4 "2019-09-05T10:44:51Z")

</div>

This was obviously not solved because I am getting the same exact error with the same exact code.  
Hoping someone like @yisrael-wix can help us out over here

This is really holding me back from going live with my new site

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [September 5, 2019, 2:01pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/5 "2019-09-05T14:01:46Z")

</div>

No idea how to help since you have not provided any code or other information that would indicate what you’re trying to do, and what is happening in fact.

---

<div class="post-metadata">

**Author:** ![mennyg19](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mennyg19/32/9941_2.png) [@mennyg19](https://forum.wixstudio.com/u/mennyg19)\
**Post date:** [September 5, 2019, 3:34pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/6 "2019-09-05T15:34:53Z")

</div>

@yisrael-wix I have the exact code as the first comment above:  
**Front-end code:**

```javascript
import { sendEmail } from "backend/emails.jsw"
$w("#sendEmail").onClick(() => {
    sendEmail("first name","last name","myemail@gmail.com","1111111111")
    .then((answer) => {
        console.log(answer)
        console.log("success")
    })
    .catch((err) => {
        console.log(err)
        console.log("error")
    });
});

```

Backend Code (emails.jsw):

```javascript
import wixCrmBackend from 'wix-crm-backend';
export function sendEmail(firstName, lastName, email, phone) {
 return wixCrmBackend.createContact( {
 "firstName": firstName,
 "lastName": lastName,
 "emails": [email],
 "phones": [phone]
  } );
}

```

When running this on my live site, I get an error, when running from the preview, I get the following error:

```javascript
Error: server responded with - {"message":"permission_denied, details: {\"RequiredRole\":\"Anonymous User or corvidBackend\",\"GivenIds\":\"member -> 2719d7ed-5eff-48b2-92ad-676777586560\"}","details":{"givenids":"member -> 2719d7ed-5eff-48b2-92ad-676777586560","requiredrole":"Anonymous User or corvidBackend","error":"permission_denied","category":"api_error"}} (403) 

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [September 8, 2019, 9:12am UTC](https://forum.wixstudio.com/t/crm-backend/15735/7 "2019-09-08T09:12:35Z")

</div>

@mennyg19 This will not work correctly in Preview (same as wix-user). What error do you get in Live? It works OK for me, so I asked QA and it works for them as well.

---

<div class="post-metadata">

**Author:** ![mennyg19](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mennyg19/32/9941_2.png) [@mennyg19](https://forum.wixstudio.com/u/mennyg19)\
**Post date:** [September 8, 2019, 9:54am UTC](https://forum.wixstudio.com/t/crm-backend/15735/8 "2019-09-08T09:54:18Z")

</div>

@yisrael-wix I did not get any error message, This is my console in Chrome in Live. The green lines are for when I am logged out. The red line is when I am logged in. This also works for me on my old site ( [https://www.chessedvemes.com/send-emails-receipts](https://www.chessedvemes.com/send-emails-receipts) ). This is only not working on my new site ( [https://mennyg4.wixsite.com/website/blank-4](https://mennyg4.wixsite.com/website/blank-4) )

![](https://us1.discourse-cdn.com/wix/original/3X/8/2/82bc582dec2997db1e1712a82e37a211b47e2f5e.png)  
Here is the catch code again for reference:

```javascript
.then((answer) => {
        console.log(answer)
        console.log("success")
    })
    .catch((err) => {
        console.log(err)
    });

```

```
I also tried it this way with the same result:

```

```javascript
.then((answer) => {
        console.log(answer)
        console.log("success")
    })
    .catch( err => console.log(err));

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [September 8, 2019, 10:53am UTC](https://forum.wixstudio.com/t/crm-backend/15735/9 "2019-09-08T10:53:11Z")

</div>

@mennyg19 What is the error? What’s not working? Is the contact created?

---

<div class="post-metadata">

**Author:** ![mennyg19](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mennyg19/32/9941_2.png) [@mennyg19](https://forum.wixstudio.com/u/mennyg19)\
**Post date:** [September 8, 2019, 11:54am UTC](https://forum.wixstudio.com/t/crm-backend/15735/10 "2019-09-08T11:54:59Z")

</div>

@yisrael-wix The contact is not being created at all if I am logged in. If I am logged out, the contact is created

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [September 8, 2019, 1:11pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/11 "2019-09-08T13:11:08Z")

</div>

@mennyg19 You are logged in? Then what contact is being created? If you’re logged in, then are you trying to create a contact for yourself?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [September 8, 2019, 1:41pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/12 "2019-09-08T13:41:46Z")

</div>

@yisrael-wix

Yes does make perfect sense, when logged in you are already a site member so you can’t create a new contact for yourself as you already have one, all you can do is update your contact.

---

<div class="post-metadata">

**Author:** ![mennyg19](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mennyg19/32/9941_2.png) [@mennyg19](https://forum.wixstudio.com/u/mennyg19)\
**Post date:** [September 8, 2019, 3:00pm UTC](https://forum.wixstudio.com/t/crm-backend/15735/13 "2019-09-08T15:00:22Z")

</div>

@yisrael-wix Okay, so you gave me a few pointers. If logged in, I cannot create a contact.  
I tried just emailing and it works (once the contact is created), thank you.  
However, I want to create an admin page (that does not require a login to Wix Dashboard, but requires a login to the site) that can create new contacts and send emails to them. Is that impossible? What about a dashboard page? I tried doing this on a dashboard page and that does not work either.
