Home > front end >  Get Data from NameApi using google apps script?
Get Data from NameApi using google apps script?

Time:10-24

I am trying to get the data for a specific name using Error

Kindly can you guide me on what am I doing wrong in order to get this right? Thank you.

CodePudding user response:

As @Tanaike and @idfurw suggested in the comments, I want to post answer that might be helpful for someone looking for the same thing. Changing GIVENNAME to FULLNAME solved the issue and the following modified script is able to get all the required parameters in the JSON output:

function TestNameApi() {

  const apiKey = "###"; // Please set your API key.
  var url = "https://api.nameapi.org/rest/v5.3/parser/personnameparser?apiKey="   apiKey;

  var Name = {
    "context": {
      "priority": "REALTIME",
      "properties": []
    },
    "inputPerson": {
      "type": "NaturalInputPerson",
      "personName": {
        "nameFields": [{
          "string": "BRANDYN KRAMER",
          "fieldType": "FULLNAME"
        }]
      },
      "gender": "UNKNOWN"
    }
  }

  var options = {
    'method': 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(Name)
  };

  var response = UrlFetchApp.fetch(url, options).getContentText();
  Logger.log(response);

}
  • Related