Can I use a Postman Code example to code my own call?

Hi, I have a somewhat unusual situation in that I’m attempting to code the call to an API without access to either the API code or its developer. I’m able to make successful calls using Postman, but when I implement the Javascript - jQuery example under the Code tab I get an error from the API. I realize that the actual Postman call is not made using any of the listed code snippets, but am I correct in assuming they will work if implemented correctly? And if so and if my implementation is faithful to the Postman code then what might be preventing mine from working? Thanks.

Hi @LRolly44! Welcome to the community. :slight_smile:

Yes, the generated code in Postman should work, if your request is set up correctly for the API you’re using.

Can you share any errors / responses you’re getting? Difficult to diagnose what the issue is otherwise.

If you don’t want to share this info publicly, you’re welcome to open a ticket with us:

Hi John Paul,

Thanks for responding, much appreciated. I decided to open a ticket
with you since some of the information should likely stay private. I’m
assuming I will be notified via email of any response, but I’ll also
check in with the Postman site regularly. Thanks again.

Onward,
Steve

Hi John Paul,

Here are the two code versions, one from Postman, the other my own.
Following the Postman sample is the valid response from the API.
Following my implementation of the generated code is the error message
generated by the API. I believe my code is a faithful implementation of
the code generated by Postman in its successful call. What I would like
is confirmation of that so I can pursue whether the API may have some
flaw itself. Thanks for considering this.

First the Postman sample code from the Code tab (Javascript - jQuery)
generated in conjunction with the successful call:

var settings = {
“url”:
“https://www.TheirSite.com:443/score.php?returntransfer=true&ssl-verifypeer=false&connecttimeout=10&customrequest=get&content-type=application/json;
charset=utf-8&content-length=247”,
“method”: “GET”,
“timeout”: 0,
“headers”: {
“Authorization”: “TheID”
},
“data”:
“{“testdate”:“10-10-2019”,“grade”:2,“age”:18.10,“scores”:[{“score”:34,“subtest”:“vocab”},{“score”:23,“subtest”:“comp”},{“score”:402,“subtest”:“readingrate”}],“form”:“J”,“studentid”:10711,“scoringtype”:2,“norms”:“grade”,“customerid”:“commcolleges”}\r\n”,
};

$.ajax(settings).done(function (response) {
console.log(response);
});

Then the valid response to Postman (JSON format):
{
“studentid”: “10711”,
“vocabrs”: 34,
“vocabss”: “105”,
“vocabpr”: "“63"”,
“vocabsem”: “3”,
“vocabge”: "“12.2"”,
“comprs”: 23,
“compss”: “117”,
“comppr”: ““87"”,
“compsem”: “5”,
“compge”: “”> 17"”,
“readingrate”: 402,
“readingratess”: “124”,
“readingratepr”: "“95"”,
“readingratesem”: “5”,
“indexsum”: 222,
“gra”: “113”,
“grapr”: "“81"”,
“grasem”: “3”
}

Here is my code (sans the html wrap and “script /script” tags):

<script type="text/javascript" src="/CFIDE/scripts/ajax/jquery/jquery-3.4.1.min.js"></script>

{
function jcall(){
var settings = {
“url”: “https://www.TheirSite.com:443/score.php?returntransfer=true&ssl-verifypeer=false&connecttimeout=10&customrequest=get&content-type=application/json; charset=utf-8&content-length=247”,
“method”: “GET”,
“timeout”: 0,
“headers”: {
“Authorization”: “TheID”,
“Content-Type”: “text/plain”
},
“data”: “{“testdate”:“10-10-2019”,“grade”:2,“age”:18.10,“scores”:[{“score”:34,“subtest”:“vocab”},{“score”:23,“subtest”:“comp”},{“score”:402,“subtest”:“readingrate”}],“form”:“J”,“studentid”:10711,“scoringtype”:2,“norms”:“grade”,“customerid”:“commcolleges”}\r\n”,
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
}

}

The error response from my code :

{“error_code”:“Error 3”,“message”:“Either your customerid is incorrect, your API Key is incorrect, or you do not have the rights to score J.”}

The API developer got back to me with corrections to my (and Postman’s code) that made the call work. Yea, this thread is finished, thanks.