CA
genetic-orange

How to input specific URLs?

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:
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);
});
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);
});
5 Replies
Alexey Udovydchenko
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.
genetic-orange
genetic-orangeOP2y ago
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:
const input = await Actor.getInput<InputSchema>();
let companyWebsites: string[] | undefined = input?.companyWebsites;

companyWebsites?.forEach(function (companyWebsite) {
console.log("validating companyWebsites");
console.log(companyWebsite);
});
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 @Apify
unwilling-turquoise
unwilling-turquoise2y ago
Hey! Use: console.log(companyWebsite.url); . This probably happened because you used "editor": "requestListSources" in the input schema file.
genetic-orange
genetic-orangeOP2y ago
@lemurio Hi, The schema looks like this so there is no url property:
interface InputSchema {
companyWebsites: string[];
sortBy: string;
filterByStarRating: string;
filterBylanguage: string;
filterByVerified: string;
startFromPageNumber: number;
endAtPageNumber: number;
}
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?
unwilling-turquoise
unwilling-turquoise2y ago
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
"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/"]
}:
"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/"]
}:
Specification (v1) | Platform | Apify Documentation
Learn how to define and easily validate a schema for your Actor's input with code examples. Provide an autogenerated input UI for your Actor's users.

Did you find this page helpful?