Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
How to change Python to Apps Script get api?

I want to change python to apps script in apps script have UrlFetchApp function i'm never use but i'm try
I have code python can get api normally

import requests
 
url = "https://api.aiforthai.in.th/ssense"
 
text = 'Have a good day'
 
params = {'text':text}
 
headers = {
    'Apikey': "xxx-xxx-xxx"
    }
 
response = requests.get(url, headers=headers, params=params)
 
print(response.json())

so now i'm try code apps script like this but notthing came out ; Api dashboard call me i'm use api.
maybe wrong payload text?

Detail API

  • Host
    https://api.aiforthai.in.th/ssense

  • Method
    GET/POST

  • Header
    Apikey : xxx-xxx-xxx Content-Type : application/x-www-form-urlencoded

  • Parameter
    text : text for analysis

This my wrong apps script code

function call_api() {
  var url = "https://api.aiforthai.in.th/ssense"

  var apiKey = "xxx-xxx-xxx";

  var response = UrlFetchApp.fetch(
    url,
    {
      "headers": {
        "Apikey": apiKey,
        "text": "Have a good day"
      }
    }
  )
  Logger.log(response)
}

Thank you for solution.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I believe your goal is as follows.

  • You want to convert the following python script to Google Apps Script.

      import requests
    
      url = "https://api.aiforthai.in.th/ssense"
    
      text = 'Have a good day'
    
      params = {'text':text}
    
      headers = {
          'Apikey': "xxx-xxx-xxx"
          }
    
      response = requests.get(url, headers=headers, params=params)
    
      print(response.json())
    
  • You have already been confirmed that your python script worked fine.

When I saw your python script, text is sent as the query parameter. In this case, how about the folloiwng modification?

Modified script:

function call_api2() {
  var text = "Have a good day";
  var url = `https://api.aiforthai.in.th/ssense?text=${encodeURIComponent(text)}`;
  var apiKey = "xxx-xxx-xxx";
  var response = UrlFetchApp.fetch(
    url,
    { "headers": { "Apikey": apiKey } }
  );
  Logger.log(response.getContentText());
}

Note:

  • If you test the above modified script, when an error occurs, please confirm your apiKey again.
  • If an error like status code 403 occurs, your URL might not be able to be requested from Google side. I'm worried about this.
about 4 years ago · Juan Pablo Isaza Report

0

Try this instead:

function call_api() {
  var url = "https://api.aiforthai.in.th/ssense";

  var apiKey = "xxx-xxx-xxx";

  var response = UrlFetchApp.fetch(
    url,
    {
      "method" : "GET",
      "headers" : {
        "Apikey" : apiKey,
        "text" : "Have a good day"
      }
    }
  );
  Logger.log(response)
}

You can check out the UrlFetchApp documentation for future reference.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!