2

I'm pretty new to Magento and I was trying to add a media to a existing product. From code I am able to do that as the following:

$entry = ['entry' => [
            'media_type' => ---,
            'position' => ---,
            'types' => [
                ---,
                ---,
                ---,
            ],
            'file' => ---,
            'content' => [
                'base64_encoded_data' => base64_encode(---),
                'type' => ---,
                'name' => ---,
            ]
        ]
        ];
        if (---) {
            $entry['entry']['id'] = ---;
        }

        $saveMedia->whereSku($sku)
            ->withData($entry)
            ->save();

The code is working "fine" I am actually trying to use a POST to update an existing image specifing the id but that part it's not working and I get a new image. When I got this error I tried to do the same POST in postman and when I specify in the body the same code as above in json the following error appears:

{
    "message": "%fieldName is a required field.",
    "parameters": {
        "fieldName": "entry"
    },
}

My json is as following:

{"entry":{"media_type":"---","position":---,"types":["image","small_image","thumbnail"],"file":"---","content":{"base64_encoded_data":"---","type":"image\/jpeg","name":"---"},"id":---}}

So:

  • How do I fix this error? Why isn't my entry recognized?

1 Answer 1

1

The error was that inside Postman I tried to add inside the body a "form-data" with the wrong key.. If I paste the same json as above inside "raw" body everything works fine!

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.