Building a custom API from scratch using Sunshine

Have more questions? Submit a request

7 Comments

  • Azhar
    Comment actions Permalink

    While posting the data using API request to create a doggo record, we are getting 404 error. We have checked all the configurations and files and it looks fine to us as per the article above.

    Getting below error :

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
    <head>
    <title>Error: 404 Not Found</title>
    <style type="text/css">
    html {background-color: #eee; font-family: sans-serif;}
    body {background-color: #fff; border: 1px solid #ddd;
    padding: 15px; margin: 15px;}
    pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}
    </style>
    </head>
    <body>
    <h1>Error: 404 Not Found</h1>
    <p>Sorry, the requested URL
    <tt>&#039;http://localhost:8080/api/doggos&#039;</tt>
    caused an error:
    </p>
    <pre>Not found: &#039;/api/doggos&#039;</pre>
    </body>
    </html>

    0
  • Charles Nadeau
    Comment actions Permalink

    Hi Azhar,

    404 means the server couldn't find the file, which in Bottle terms means it couldn't find a route to the endpoint. Can you check the endpoint's route in your doggo_api.py file. It should be:

    @route('/api/doggos', method='POST')

    0
  • Azhar
    Comment actions Permalink

    Hi Charles,

    Yes, the endpoint route in my doggo_api.py is exactly same as what you mentioned but I am receiving the 404 error every time I am running the python file normally and hitting the POST or GET request either form POSTMAN or CURL. 

    Whenever I am executing the doggo_api.py file in debug mode using -m pdb then for the first time when the code reaches on fetching json request after establishing connection getting failed  but upon several attempt  it is able to post successfully and I am receiving the response  i.e. only when debug mode is on and connection getting establish upon repeating after failing once, we are receiving the response. I am exactly clueless of this weird situation now.

     

    Normal Scenrio :

     

    Debug Mode Scenario  (after repetitive attempt):

     

    We want flawless consistent response. Need help in this regards.

    0
  • Charles Nadeau
    Comment actions Permalink

    Strange. I retested the app this morning and it still works for me. I notice in your Postman screenshots that you included the "-v" verbose flag in the endpoint URL. The field is a web address, not a curl statement. The extra "-v" will return a 404 error. You didn't include the -v flag in the example that worked.

    0
  • Azhar
    Comment actions Permalink

    That -v  might be due to the copy-paste. But it didn't worked for me without that flag too in normal scenario. Please find the screen shot below :

     

    Let me know if I can attach my files somewhere which I am running to achieve the result,so that you can simply run my file and can detect if by mistake I have been doing something incorrect in the file.

     

    0
  • Suman Saha
    Comment actions Permalink

    Hi Charles,

    I have created this api and is working fine. I'm able to access data with api calls for e.g.

    http://localhost:8080/api/owners/407611529753/doggos

    Now I need to call the same API from a custom app, that I have built in Zendesk Support and display the data there for the same user (with id 407611529753).

    How do I call the API?

    I tried the below but it did not work. 

    function requestUserInfo(client, id) {
    var settings = {
    //url: '/api/v2/users/' + id + '.json',
    url: 'api/sunshine/objects/records/zen:user:' + id + '/related/owner_has_many_doggos',
    type:'GET',
    dataType: 'json',
    };

    Can you pls help me or direct me to some documentation where I can find some help.

    Also just a thought is it something to do with the datatype that is getting returned?

    the same urlis working in Postman:

    Thanks,

    Suman

    0
  • Charles Nadeau
    Comment actions Permalink

    Hi Suman,

    I noticed a slash is missing at the beginning of the url property:

    url: 'api/sunshine/objects/records/zen:user:' + id + '/related/owner_has_many_doggos',

    Maybe that's the culprit? Can you try:

    url: '/api/sunshine/objects/records/zen:user:' + id + '/related/owner_has_many_doggos',
    0

Please sign in to leave a comment.

Powered by Zendesk