Part4 Quiz Error

Not applicable

Hi

I have completed the excercise but when i submit ,it says below. Kindly help

not good... Which is to say, the response that came back wasn't something we expected so it's hard to say what went wrong. Here's what we got back.http://vikaslall-test.apigee.net/v1/humor/joke?jokeid=3229&apikey=EQrz0wsK5IgO9e8wWebQXT0n8G8DeTGM

HTTP status: 200 { "jokeid":"3229", "title":"Advice for Idiots", "body":"An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for Employees": \n\n "Blink your eyelids periodically to lubricate your eyes."", "rating":"G", "img":"", "modified":"2000-07-31" "comments":"[This joke is cooool,This is very funny]" }

Solved Solved
0 9 459
1 ACCEPTED SOLUTION

Not applicable

I ran your API and found that your response still has the extra \n characters in it that the Javascript callout was supposed to fix.

Here is the response I got:

 {
  "jokeid":"3229",
  "title":"Advice for Idiots",
  "body":"An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for  Employees": \n\n "Blink your eyelids periodically to lubricate your  eyes."",
  "rating":"G",
  "img":"",
  "modified":"2000-07-31"
  "comments":["This is very funny",
               "OMG so funny!"
        ]
}

Here is a typical response that is expected:

{
    "jokeid": "3229",
    "title": "Advice for Idiots",
    "body": "An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for  Employees":  "Blink your eyelids periodically to lubricate your  eyes."",
    "rating": "G",
    "img": "",
    "modified": "2000-07-31",
    "comments": [
        "Hi There",
        "This is a comment2"
    ]
}

Notice that the \n's are removed. Your Javascript should look something like this:

var myvar = context.getVariable("jokeresponse.body");
myvar = myvar.replace("\\n", "", "g");
context.setVariable("jokeresponse.body", myvar);

You should attach the Javascript callout to the Joke Details response. Within trace you should be able to see the jokeresponse.body changed to delete those characters.

I believe you are failing because of the extra \n characters in the response body. If you can get your Javascript callout to remove them and you are still failing, please let us know at help@apigee.com and we'll adjust your grade accordingly. It does appear that your callout to the comments database is working correctly, so you are quite close.

View solution in original post

9 REPLIES 9

Not applicable

I feel the reason is that the jokeindex server is returning correctly formatted response with " \\n "and now that problem which we intended to fix using Javascript fix has resolved. But now the test tool probably is evaluating keeping that in mind and hence failing me .

Not applicable

Hi Anyone there?

Not applicable

We are currently in the process of revamping our exam tool. We occasionally see problems where a correct answer is graded incorrectly. If your proxy is working correctly but being graded as a fail, please contact help@apigee.com and we will update the grade to a pass.

Not applicable

I ran your API and found that your response still has the extra \n characters in it that the Javascript callout was supposed to fix.

Here is the response I got:

 {
  "jokeid":"3229",
  "title":"Advice for Idiots",
  "body":"An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for  Employees": \n\n "Blink your eyelids periodically to lubricate your  eyes."",
  "rating":"G",
  "img":"",
  "modified":"2000-07-31"
  "comments":["This is very funny",
               "OMG so funny!"
        ]
}

Here is a typical response that is expected:

{
    "jokeid": "3229",
    "title": "Advice for Idiots",
    "body": "An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for  Employees":  "Blink your eyelids periodically to lubricate your  eyes."",
    "rating": "G",
    "img": "",
    "modified": "2000-07-31",
    "comments": [
        "Hi There",
        "This is a comment2"
    ]
}

Notice that the \n's are removed. Your Javascript should look something like this:

var myvar = context.getVariable("jokeresponse.body");
myvar = myvar.replace("\\n", "", "g");
context.setVariable("jokeresponse.body", myvar);

You should attach the Javascript callout to the Joke Details response. Within trace you should be able to see the jokeresponse.body changed to delete those characters.

I believe you are failing because of the extra \n characters in the response body. If you can get your Javascript callout to remove them and you are still failing, please let us know at help@apigee.com and we'll adjust your grade accordingly. It does appear that your callout to the comments database is working correctly, so you are quite close.

The slash-n characters don't display as expected on the forum site. Line 2 of the Javascript should be

myvar = myvar.replace("<slash><slash>n", "g");

where <slash> is the actual slash character.

Not applicable

@Michael Malloy Thanks Michael, done exactly as suggested and now i don't see any newline characters in response but still its shows "Not Good" .

MY URL

http://vikaslall-test.apigee.net/v1/humor/joke?jok...

Response Now

HTTP/1.1 200 OK Cache-control: no-cache,no-store,must-revalidate X-server: jokeindex.com Transfer-Encoding: chunked Modified: now Date: Sat, 04 Oct 2014 19:48:49 GMT Expires: Sat, 04 Oct 2014 19:48:49 GMT Keep-Alive: timeout=15, max=100 Etag: Sat, 04 Oct 2014 14:48:49 CDT Set-Cookie: CGISESSID=332cd2cb4c8f7a6a67b149be7c3560fa; path=/ Content-Type: application/json Server: Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze19 with Suhosin-Patch mod_ssl/2.2.16 OpenSSL/0.9.8o Pragma: No-cache

{ "jokeid":"3229", "title":"Advice for Idiots", "body":"An actual tip from page 16 of the HP "Environmental,Health & Safety Handbook for Employees": "Blink your eyelids periodically to lubricate your eyes."", "rating":"G", "img":"", "modified":"2000-07-31" "comments":["This is very funny", "OMG so funny!" ] }

Not applicable

Below is the JS

var myvar=context.getVariable("jokersp.body"); myvar= myvar.replace("\\n"," ","g"); context.setVariable("jokersp.body",myvar);

Not applicable

The extraneous newline characters are gone now, which is good. If you're still having a problem with the exam software, send an email to help@apigee.com with the url that demonstrates the problem and we'll look into it for you.

Not applicable

Thanks was able to pass week 4 test .