1

I'm trying to add custom data to an order using the REST API.

I have added code which GETS the data from the database, but i'm now looking at how to set this using the REST API.

I have written code, which have relevant getters / setters in OrderExtension, and the name of the field is appearing in the swagger -

enter image description here

enter image description here

However, when I try to use this I get this error back -

enter image description here

Is it possible to update this part of an order once it has been placed? Would I need to create my own endpoint to do this? Or would I need to add it to quote, and then order?

1 Answer 1

0

Your sort_code field is part of extension_attributes for the order, so you need to pass it as such. Note how it's looking for your field on OrderInterface, instead of on OrderExtensionInterface where it is.

To do that, taking your example, wrap your field in extension_attributes like so:

{
    "entity": {
        "entity_id": 7,
        "extension_attributes": {
            "sort_code": 321321
        }
    }
}

That should map it through correctly.

2
  • I tried this, and the endpoint does accept the data. However, if I then do a GET to the specified order, it doesn't give back the data that was passed to it.
    – BigDaddyL
    Commented Nov 29, 2017 at 9:07
  • That suggests your ExtensionAttribute isn't set up fully. You have to have plugins to save data from the extension attr, AND to load data into it. Note for loading that the process can be different for one (getById) versus many (getList). One calls singular load, the other uses a collection. That usually means two distinct load plugins.
    – Ryan Hoerr
    Commented Nov 29, 2017 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.