---
title: "REST - Create"
canonical: "https://help.agiloft.com/space/HELP/43714571/REST+-+Create"
format: markdown
---
> Macro (anchor)

The EWCreate (POST) operation creates a record in the specified KB and table, and can include values for specified fields.

- **Returns**: the ID of the newly created record.
- **Supported Content-Type**: <span style="color: #505050">application/</span>x-www-form-urlencoded
- Compatible with [EWAsyncStatus](https://wiki.agiloft.com/display/PROD/REST+-+Async+Status). If you use this operation asynchronously, you can use EWAsyncStatus to check its status.
- Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see [REST Interface](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

## Example

Assume an instance of Agiloft is available on localhost, port 8080 and is called "Demo". Create a record for an employee named John Doe, that is assigned to the Service Manager group and Service Management Team, with login 'jdoe' and password 'password'.

Also, assume an instance of Agiloft is available on localhost. 

- The Employee table is a sub-table of Contacts (logical table name = contacts.employees).
- To create the user we need to fill in the first_name, last_name, _login and password fields.
- We also need to create links with the groups and teams tables via linked fields that import multi-value fields groups and teams and a single-value field primary team.
- We will use an example query and supply the names of the Service Manager group and Service Management Team.

The following request is issued: 

```xml
https://localhost:8080/ewws/EWCreate?$KB=Demo&$table=contacts.employees&$login=admin&$password=qwerty&$lang=en&first_name=John&last_name=Doe&_login=jdoe&password=password&f_group=:Service Manager&teams=:Service Management Team&_106_sw_description=:Service Management Team&_1576_company_name0=:Agiloft
```

A result similar to the following will be returned in the case of successful record creation: 

```xml
EWREST_id='353'; 
```

## JavaScript Example

Here is an example of a JavaScript-based client that invokes the REST interface via AJAX: 

```javascript
     function xmlhttpGet (strURL) {
        var xmlHttpReq=false;
        var self=this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            try {
                netscape.security.PrivilegeManager.
                  enablePrivilege("UniversalBrowserRead");
            } catch (e) {
                alert("Permission UniversalBrowserRead denied.");
            }
            self.xmlHttpReq=new XMLHttpRequest();
        }// IE
        else if (window.ActiveXObject) {
            self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP");
        }
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.onreadystatechange=requestComplete;
        self.xmlHttpReq.send(null);
    }
    function requestComplete() {
        if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") {
            eval (self.xmlHttpReq.responseText);
            alert ("Id of new ticket"+EWREST_id);
        }
    }
    function main() {
        xmlhttpGet('https://localhost:8080/ewws/EWCreate?$KB=Demo&$table=contacts.employees&$login=admin&$password=qwerty&$lang=en&first_name=John&last_name=Doe&_login=jdoe&password=password&f_group=:Service
Manager&teams=:Service ManagementTeam&_106_sw_description=:Service ManagementTeam&_1576_company_name0=:Agiloft');
    }
```

## Generate an HTML Form

You can generate an HTML form that submits a request to the REST EWCreate operation to create a record in a selected table. To start with a sample, you can generate one from your KB:

1. Navigate to **Setup** **[Table]**
2. Click the API tab.
3. Select the name to use for the record creator.
4. Choose which layout you'd like the HTML code sample to use.
5. Click Download HTML.

# Error Codes

These error codes are for EWCreate only, but are not an extensive list of possible error codes. For any errors not listed here, consult the General Error Codes section of [https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

|  |  |  |  |
| --- | --- | --- | --- |
| Error Scenario | Type | Error Code | Error Description |
| When the provided value is not valid format | VALIDATION | 400 | EWWrongDataException → Wrong format/value pointed to <columnName> |
| Error with respect to Linked/mixed fields | VALIDATION | 400 | EWWrongDataException → multiple values are not allowed for Linked Filed <fieldName> |
| EWWrongDataException → mixed linked and allowExtra values for Linked Filed <fieldName> |
| EWWrongDataException → Multiple values found with condition <searchCondition> are not allowed for Linked Filed <fieldName> |
| EWWrongDataException → No linked records found for Linked Filed <fieldName> with condition <searchCondition> |
| EWWrongDataException → Expected String or String[] value for multi-value column <columnName> in QBE criteria |
| EWWrongDataException → Extra multi-values are only allowed to a strict Link Field |
| EWWrongDataException → Expected String[<numberOfValues>] for the extra values in Linked Field <fieldName> column <importedFieldName> |

  


> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)