Hi, I’m trying to implement the REST API in my application written in Python3.
I’m very new to this kind of REST stuff so please forgive my lack of experience.
My first question is about the enpoint:
The web services are accessible ws endpoint, for example:
http://localhost:8080/open-platform-demo/ws/
I run Axelor in a windows docker and the end point seems to be :
http://localhost:8080/ws/
is it correct ? or must I use another endpoint ? wich one in my case ?
Here is the python code I tried:
import requests
auth_data = {
"username": "admin",
"password" : "admin"
}
new_contact = {
"data": {
"firstName": "John",
"lastName": "Smith",
"email": "j.smith@gmail.com",
}
}
# Connect and authenticate
resp = requests.post('http://localhost:8080/ws/login.jsp', )
if resp.status_code != 200:
print(f'ERROR POST /login.jsp/ status code = {resp.status_code}')
else :
print (f'SUCCESS POST /login.jsp/ status code = {resp.status_code}')
# Read a record
resp = requests.get('http://localhost:8080/ws/rest/com.axelor.contact.db.Contact')
if resp.status_code != 200:
print(f'ERROR GET /ws/rest/com.axelor.contact.db.Contact/ status code = {resp.status_code}')
else:
print(f'SUCCESS GET /ws/rest/com.axelor.contact.db.Contact/ status code = {resp.status_code}')
# Create a new record
resp = requests.post('http://localhost:8080//ws/rest/com.axelor.contact.db.Contact', json=new_contact)
print (f'status code = {resp.status_code}')
if resp.status_code != 201:
print(f'ERROR GET /ws/rest/com.axelor.contact.db.Contact/ status code = {resp.status_code}')
else :
print(f'Created contact. firstName: {resp.json()["firstName"]}')
This give me the following results:
SUCCESS POST /login.jsp/ status code = 200
SUCCESS GET /ws/rest/com.axelor.contact.db.Contact/ status code = 200
status code = 401
ERROR GET /ws/rest/com.axelor.contact.db.Contact/ status code = 401
I think I miss something basic.
Thanks in advance,
Best regards,
Rafael