API


Getting Started

HTTP Methods 

GET
POST
PUT
DELETE


PUT

Model records:

PUT /api/{model}/

Headers 

  • Content-Type: application/json

Parameters

  • data (mandatory):

    This is used to pass data to update, it works with filter parameter, See example below

  • filter (mandatory):

    This is used to filter data to update. For example

    PUT /api/product.template/

    Request Body

                          {
        "params": {
            "filter": [["id", "=", 95]],
            "data": {
                "name": "Test product"
            }
        }
    }
    
                        

    Response

                          {
        "jsonrpc": "2.0",
        "id": null,
        "result": true
    }
    
                        

    Note: If the result is true it means success and if false or otherwise it means there was an error during the update.

  • context (optional): Just like in GET context is used to pass any context associated with record update. The format of passing it is

    Request Body

                          {
        "params": {
            "context": {
                "context_1": "context_1_value",
                "context_2": "context_2_value",
                ....
            },
            "filter": [["id", "=", 95]],
            "data": {
                "field_1": "field_1_value",
                "field_2": "field_2_value",
                ....
            }
        }
    }
    
                        
  • operation (optional):

    This is only applied to one2many and many2many fields. The concept is sometimes you might not want to replace all records on either one2many or many2many fields, instead you might want to add other records or remove some records, this is where put operations come in place. There are basically three PUT operations that are push, pop, and delete.

    • push is used to add/append other records to existing linked records
    • pop is used to remove/unlink some records from the record being updated but it doesn't delete them on the system
    • delete is used to remove/unlink and delete records permanently on the system

    For example here is how you would update related_product_ids which is many2many field with PUT operations

    PUT /api/product.template/

    Request Body

                          {
        "params": {
            "filter": [["id", "=", 95]],
            "data": {
                "related_product_ids": {
                    "push": [102, 30],
                    "pop": [45],
                    "delete": [55]
                }
            }
        }
    }
    
                        

    This will append product with ids 102 and 30 as related products to the product with id 95 and from there unlink the product with id 45 and again unlink the product with id 55 and delete it from the system. So if before this request product with id 95 had [20, 37, 45, 55] as related product ids, after this request it will be [20, 37, 102, 30].

    Note: You can use one operation or two or all three at a time depending on what you want to update on your field. If you don't use these operations on one2many and many2many fields, existing values will be replaced by new values passed, so you need to be very careful on this part.

    Response:

                          {
        "jsonrpc": "2.0",
        "id": null,
        "result": true
    }
    
                        

Model record:

PUT /api/{model}/{id}

Headers

  • Content-Type: application/json

Parameters

  • data (mandatory)
  • context (optional)
  • PUT operation(push, pop, delete) (optional)

All parameters works the same as explained on previous section, what changes is that here they apply to a single record being updated and we don't have filter parameter because id of record to be updated is passed on URL as {id}. Example to give us an idea of how this works.

PUT /api/product.template/95/

Request Body

                {
    "params": {
        "data": {
            "related_product_ids": {
                "push": [102, 30],
                "pop": [45],
                "delete": [55]
            }
        }
    }
}