Hi,
I tried following the documentation on REST API for POST (CRUD Operations, Create).
I have successfully fired a GET onto my erpnext instance, which tells you both my url and security tokens are ok. But when I fired by POST, i got a 200 HTTP Response with a list of documents from that Doctype
For the Body, I am passing a json object as follows
{
"employee": "ABCD", // linked record
"production_order": "ABC", // linked record
"date": "2022-12-02", // simple date as a string.
"result": 2, // integer
"time": 555 // integer
}
But for the result of this, I am getting:
200 OK and this…
{
“data”: [
{
“name”: 2
},
{
“name”: 3
}
]
}
What am I missing??
Ok, looking into the generated timeline, it seems that there was an issue:
- Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 02 Dec 2022 12:42:13 GMT
< Content-Type: text/html
< Content-Length: 162
< Connection: keep-alive
< Location: https://***************/api/resource/Quality%20Session%20Data
< Server: Frappe Cloud
- Ignoring the response-body
- Received 162 B chunk
- Connection #49 to host www.indopar.com.py left intact
- Issue another request to this URL: ‘https://**********/api/resource/Quality%20Session%20Data’
- Switch from POST to GET
So in effect, the POST gets converted into a GET so as not to return blank. But regardless, why does it show a 301 Moved Permanently? My Doctype is correct, because if I try to misspell, it returns a doctype not found error.
Plus I have also checked that my user has permisions to create, read, write, and delete this document. I have been able to personally add records through frappe interface. Just can’t get it done through an api.
Any thoughts??
Ok, solution found.
I was hitting HTTP, instead of HTTPS. The redirection gave me a clue regarding that, i just assumed that since the Nginx or Apache automatically shifts to https, the api would do the same.