1

I tried looking for answers before posting but couldn't find any.

I hosted my magento site in siteground and added integration.

Then I tried accessing the API using Postman but I get either 401 error or could not get any response.

Can someone help me with this?

enter image description here

UPDATED: Turns out the problem is on the hosting site. Tried accessing on localhost and its working. But when I tried accessing in my host server I got 401. Any idea? I'm using siteground for hosting my magento.

4
  • 1
    you might want to rotate your credentials as your tokens are now public via your screenshot Commented Mar 2, 2020 at 22:58
  • @KristofatFooman its okay its still under construction. So no data for now. Might do it after fixing the issue.
    – Daniel_C
    Commented Mar 3, 2020 at 16:57
  • here is the video about rest api access levels youtu.be/9OpjTwifhaE Commented Jul 13, 2020 at 20:00
  • did you find any solution? because the same issue occur from my side and same hosting i used right now. Commented Feb 19, 2021 at 10:39

1 Answer 1

1

If you are using token-based authentication, create a web services user on Magento Admin by selecting System > Permission > All Users > Add New User. (If you are using session-based or OAuth authentication, you do not need to create the new user in the Admin.)

Create a new integration on Magento Admin. To create an integration, click System > Extensions > Integration > Add New Integration. Be sure to restrict which resources the integration can access.

Use a REST or SOAP client to configure authentication.

Sample code snippet to check in postman

API Endpoint : magento_host_url/rest/V1/products/types

Method : GET

Headers:
**Key**                  **value**
Content-type :   application/json
Authorization :  Bearer youraccesstoken  

(here you need to place your Access Token which you get from System > Extensions > Integration > Edit.)

Response you will get is like below :

[
    {
        "name": "simple",
        "label": "Simple Product"
    },
    {
        "name": "virtual",
        "label": "Virtual Product"
    },
    {
        "name": "configurable",
        "label": "Configurable Product"
    },
    {
        "name": "downloadable",
        "label": "Downloadable Product"
    },
    {
        "name": "grouped",
        "label": "Grouped Product"
    },
    {
        "name": "bundle",
        "label": "Bundle Product"
    }
]

Please find below screenshot for more information. enter image description here

If above code is working or useful for you then upvote the answer and mark the answer as accepted so that other users can easily identify the answer.

3
  • I'm using the session-based and tried your answer but no luck. I tried this. API Endpoint: splashm2.sg-host.com/rest/V1/products/types Method: GET Headers: Key value Content-type : application/json Authorization : Bearer myaccesstoken But still no luck.
    – Daniel_C
    Commented Mar 3, 2020 at 16:57
  • I think this is not from magento. I think this issue is caused by the siteground. Because I tried calling the API from my local and its was a success. But when I tried called it from siteground host, it gave me 401 error.
    – Daniel_C
    Commented Mar 3, 2020 at 20:52
  • 1
    it is working in default magento i have cross verified with 2-3 instances, if you are facing issue with service provider then do contact them might be there are restrict some external API calls or some ports may be disable in your server. i have edited my answer with working screenshot for reference.
    – Rik Patel
    Commented Mar 4, 2020 at 4:05

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.