Skip to content
Developerhome

Mutation: Record creation

  Less than to read

A creation starts with a mutation on a specific node.

For creation, you need to enter a create() section. The create() section must include a data section that describes the JSON payload of the record to create. Lines are in JSON arrays of line structures, but you can also have a single sub-level structure, such as the internal note.

After the data section, there is a section that describes the data to be returned. In this section, the API asks for the document number, the internal ID, and the order date.

The following table displays an example and the result of a mutation to create a record. Some of the fields displayed are not mandatory and others have been omitted.

mutation { 
    xtremSales { 
        salesOrder { 
            create( 
                data: { 
                    soldToCustomer: "#FR001", 
                    salesSite: "#700", 
                    requestedDeliveryDate: "2023-03-05", 
                    lines:[ 
                        { 
                            item: "#TR-AS-1", 
                            internalNote: { 
                                value:"<h1>Info</h1><p>GraphQL training</p>"
                            }, 
                            quantityInSalesUnit: 10, 
                            stockSite: "#700", 
                            grossPrice: 120 
                        }, 
                        { 
                            item: "#LGL001", 
                            quantityInSalesUnit: 200, 
                            stockSite: "#700", 
                            grossPrice: 10.15 
                            } 
                    ] 
                }
            ),
            { 
                number 
                _id 
                orderDate 
            } 
        } 
    } 
} 
    
{ 
    "data": { 
        "xtremSales": { 
            "salesOrder": { 
                "create": { 
                    "number": "SO230010", 
                    "_id": "602", 
                    "orderDate": "2023-03-17" 
                } 
            } 
        } 
    }, 
    "extensions": { 
        "diagnoses": [] 
    }
} 

If the API call fails, the return payload has an additional error section. For example, this is what happens when your stock site does not exist. The user entered #7000 instead of #700:

{ 
    "errors": [ 
        { 
            "message": "Site: Record not found: {\"_id\":\"#7000\"}", 
            "locations": [ 
                { 
                    "line": 4, 
                    "column": 7 
                } 
            ], 
            "path": [ 
                "xtremSales", 
                "salesOrder", 
                "create" 
            ], 
            "extensions": { 
                "code": "data-input-error", 
                "diagnoses": [ 
                    { 
                        "severity": 3, 
                        "message": "Site: Record not found: {\"_id\":\"#7000\"}", 
                        "path": [] 
                    } 
                ] 
            } 
        } 
    ], 
    "data": { 
        "xtremSales": { 
            "salesOrder": { 
                "create": null 
            } 
        } 
    }, 
    "extensions": { 
        "diagnoses": [] 
    } 
}