Skip to main content
reformatted for better understanding
Source Link

Magento 2.0 API response is not in JSON format

Unable to get JSON response while using POST/PUT call

end point ->  http://magentohost/rest/default/V1/categories/4/products

Whilein JSON format with POST/PUT requests for adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the

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

The request which I am sending has a header withAPI: catalogCategoryLinkRepositoryV1 -> /V1/categories/{categoryId}/products

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

Header:

Content-Type and Authorization and: application/json Authorization:

Request body as below in JSON format,:

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

Response: "true"

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

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

Magento API response is not in JSON format

Unable to get JSON response while using POST/PUT call

end point ->  http://magentohost/rest/default/V1/categories/4/products

While adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the link http://devdocs.magento.com/swagger/index.html#/

The request which I am sending has a header with Content-Type and Authorization and body as below in JSON format,

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

The response which I get is a plain string "true" when the status code is "200 OK". But for any other status code we get a proper JSON response.

Magento 2.0 API response is not in JSON format

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

Header:

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"?

Unable to get JSON response while using POST/PUT call end point -> http://magentohost/rest/default/V1/categories/4/productsPOST/PUT call

end point ->  http://magentohost/rest/default/V1/categories/4/products

While adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1/V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the link http://devdocs.magento.com/swagger/index.html#/

The request which I am sending has a header with Content-Type and Authorization and body as below in JSON format,

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

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

The response which I get is a plain string "true" when the status code is "200 OK". But for any other status code we get a proper JSON response.

Unable to get JSON response while using POST/PUT call end point -> http://magentohost/rest/default/V1/categories/4/products

While adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the link http://devdocs.magento.com/swagger/index.html#/

The request which I am sending has a header with Content-Type and Authorization and body as below in JSON format,

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

The response which I get is a plain string "true" when the status code is "200 OK". But for any other status code we get a proper JSON response.

Unable to get JSON response while using POST/PUT call

end point ->  http://magentohost/rest/default/V1/categories/4/products

While adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the link http://devdocs.magento.com/swagger/index.html#/

The request which I am sending has a header with Content-Type and Authorization and body as below in JSON format,

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

The response which I get is a plain string "true" when the status code is "200 OK". But for any other status code we get a proper JSON response.

Source Link

Magento API response is not in JSON format

Unable to get JSON response while using POST/PUT call end point -> http://magentohost/rest/default/V1/categories/4/products

While adding/updating a Product to the category using API /V1/categories/{categoryId}/products under catalogCategoryLinkRepositoryV1 from the link http://devdocs.magento.com/swagger/index.html#/

The request which I am sending has a header with Content-Type and Authorization and body as below in JSON format,

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

The response which I get is a plain string "true" when the status code is "200 OK". But for any other status code we get a proper JSON response.