cancel
Showing results for 
Search instead for 
Did you mean: 

How can I add a custom attribute in REST API?

How can I add a custom attribute in REST API?

Question 1:
I'm trying place an order using Magento 2 API. I have a custom attribute that I want to submit along with this.
I tried submitting the custom attribute.

{
"paymentMethod": {
"poNumber": "1234567",
"method": "purchaseorder"
},
"billingAddress": {
"firstname": "Tom",
"lastname": "Sawyer",
"region": {
"region_code": "NY",
"region": "New York",
"region_id": 43
},
"region_id": 43,
"country_id": "US",
"street": [
"Main St"
],
"telephone": "64868564631",
"postcode": "11011",
"city": "New York"
},
 
"order_date": "2003-01-16 23:12:01" // my custom attribute
}


But it comes back with the error below:

Property \"OrderDate\" does not have corresponding setter in class \"Magento\\Quote\\Api\\Data\\PaymentInterface\



Question 2:
I'm trying to add a custom field to the following:
1) [GET] /V1/orders/{id}
2) [GET] /V1/orders

How can I extend Magento\Sales\Api\Data\OrderInterface?

2 REPLIES 2

Re: How can I add a custom attribute in REST API?

Hello Mykhailo7, 

I am not sure about Magento default order rest api allow to add the custom attribute to order but if you want to extend the Magento2 rest api you can check out step by step guide here.

Re: How can I add a custom attribute in REST API?

This is "... Step 3: Create webapi.xml ...", but I need to expand API.