Unable to get response in JSON format with POST/PUT requests for adding/updating a Product to the category

Reference link: http://devdocs.magento.com/swagger/index.html#/

API: catalogCategoryLinkRepositoryV1 -> /V1/categories/{categoryId}/products

End point URL -> http:///rest/default/V1/categories/4/products


Content-Type: application/json Authorization:

Request body:

  "productLink": {
    "sku": "Happiest_Minds_Bag",
    "position": 0,
    "categoryId": "4",
    "extensionAttributes": {}

Response: "true"

The response which I get is a plain string "true" with status code "200 OK". But for any other error status code for this request I get a proper JSON response.

Why am I not getting response in JSON format for status code "200 OK"?


you need to add 'Accept' => 'application/json', 'Content-Type' => 'application/json'

for example,

$token = '4hmpioj8qvtgh1d06ujgg52a52yqbmye';
$httpHeaders = new \Zend\Http\Headers();

   'Authorization' => 'Bearer ' . $token,
   'Accept' => 'application/json',
   'Content-Type' => 'application/json'
  • We did the same but still we are getting the same "true" as response 'Authorization' => 'Bearer ' . $token, 'Accept' => 'application/json', 'Content-Type' => 'application/json' Jul 8 '16 at 7:45

If you wish to receive a JSON response, you must set the Accept header of your request to application/json.

  • Tried setting Accept: application/json as header. Still the response is string "true". Jul 8 '16 at 6:52
  • The string "true" IS json. That's what you'd get from json_encode(true). It sounds like you're expecting the object you created back, but doesn't sound like that's how it works. Jul 8 '16 at 13:49
  • I am trying to parse it by using JAVA but getting exception because of a simple string. We are expecting the format in {"employees":[ {"firstName":"John", "lastName":"Doe"}, {"firstName":"Anna", "lastName":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} Jul 25 '16 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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