Apify Discord Mirror

Updated 5 months ago

How to input specific URLs?

At a glance

The community member is trying to add an input to their Apify actor that accepts a list of URLs, and they are having trouble extracting the URLs in their TypeScript code. The community members discuss different approaches, such as using a "StringList" or "JSON" editor type in the input schema, and they try to loop through the URLs, but they encounter issues where the URLs are being treated as objects instead of strings.

One community member suggests using the "stringList" editor type in the input schema and provides an example of how to specify the input schema. However, there is no explicitly marked answer in the comments.

Useful resources
I would like to add an input to my actor as such:

  • "website1.com"
  • "website2.com"
How can I do this best in the Apify input schema and how can I extract these URL strings in Typescript code?

The below approach unfortunately does not work:
Plain Text
interface InputSchema {
  companyWebsites: string[];
  sortBy: string;
  filterByStarRating: string;
  filterBylanguage: string;
  filterByVerified: string;
  startFromPageNumber: number;
  endAtPageNumber: number;
}
const input = await Actor.getInput<InputSchema>();
let companyWebsites: string[] | undefined = input?.companyWebsites;
companyWebsites?.forEach(function (companyWebsite) {
  console.log(companyWebsite);
});
A
C
R
11 comments
Aproach looks correct, you need array of string in input https://docs.apify.com/academy/deploying-your-code/input-schema then create urls from strings.
thanks should StringList or Json be used for editor type?
When I try to foreach loop the companyWebsites array and add it to an URL it seems to think it is an object instead: https://www.trustpilot.com/review/[object%20Object]?sort=recency&stars=5&languages=en&verified=true&page=2
the [object%20Object] should just be for example ebay.com
For example this:

Plain Text
const input = await Actor.getInput<InputSchema>();
let companyWebsites: string[] | undefined = input?.companyWebsites;

companyWebsites?.forEach(function (companyWebsite) {
  console.log("validating companyWebsites");
  console.log(companyWebsite);
});

Output this in console:

validating companyWebsites
{ url: 'trustpilot.com' }
I just need to output a simple sting, not an object as it does at the moment
Hey! Use: console.log(companyWebsite.url); . This probably happened because you used "editor": "requestListSources" in the input schema file.
Hi,

The schema looks like this so there is no url property:
Plain Text
interface InputSchema {
  companyWebsites: string[];
  sortBy: string;
  filterByStarRating: string;
  filterBylanguage: string;
  filterByVerified: string;
  startFromPageNumber: number;
  endAtPageNumber: number;
}

I have tried with "editor": "json" and it also fails.

Do you have other suggestions?
Is there some standard way of handling such a scenario where you need to input different uri/urls in this context?
hey, by input schema file I mean the file where you specify how the input for this actor would look like. To have the urls as a list of strings, the specification of the property could look like this
Plain Text
"urls": {
  "title": "URLs of the pages",
  "type": "array",
  "description": "The URLs of websites you want to get the data from.",
  "editor": "stringList",
  "prefill": ["https://www.apify.com", "https://docs.apify.com/"]
 }:
Add a reply
Sign up and join the conversation on Discord