user706838
user706838

Reputation: 5380

How to PATCH in flask-restless?

What is the right way to perform a PATCH request in flask-restless? I am getting the following response error:

{u'errors': [{u'status': 400, u'code': None, u'links': None, u'title': None, u'detail': u'Must specify correct data type', u'source': None, u'meta': None, u'id': None}], u'meta': {}, u'jsonapi': {u'version': u'1.0'}}

Here is my class:

class Stat(postgres.Model):

    __tablename__ = 'stats'

    def __init__(self,
        res,
        met,
        cou
    ):
        self.res = res
        self.met = met
        self.cou = cou

    id = postgres.Column(postgres.Integer , primary_key=True , autoincrement=True)
    res = postgres.Column(postgres.Enum('h' , 'd' m name='stat_res_enum') , nullable=False , unique=False)
    met = postgres.Column(postgres.Enum('u_s' , 'o_t' , name='stat_met_enum') , nullable=False , unique=False)
    cou = postgres.Column(postgres.BigInteger , nullable=False , unique=False)

Here is my request:

data = {
    "data":{
        "attributes":{
            "cou":3
        }
    }
}
response = requests.patch(url="http://127.0.0.1/api/stats/1",data=json.dumps(data),headers={'Accept' : 'application/vnd.api+json' , 'Content-Type' : 'application/vnd.api+json'})
response.json()

Upvotes: 2

Views: 1497

Answers (1)

Chervaliery
Chervaliery

Reputation: 31

You must specify the type of the data you send. Here "Stat". And for a PATCH method, you should also specify the id :

data = {
    "data":{
        "attributes":{
            "cou":3
        },
    "type": "stat",
    "id": "1"
    }
}

Upvotes: 3

Related Questions