Skip to content

feat: add subdivisionCode to proxy configuration#592

Merged
daniil-poletaev merged 7 commits into
masterfrom
feat/proxy-config-subdivision-code
Apr 28, 2026
Merged

feat: add subdivisionCode to proxy configuration#592
daniil-poletaev merged 7 commits into
masterfrom
feat/proxy-config-subdivision-code

Conversation

@daniil-poletaev

@daniil-poletaev daniil-poletaev commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

This PR adds new variable subdivisionCode and apifyProxySubdivision to Apify proxy configuration. This variable is currently needed for US state targeting.

More context: https://apify.slack.com/archives/C010Q0FBYG3/p1776704073278519

Same PR in python: apify/apify-sdk-python#878

@daniil-poletaev daniil-poletaev self-assigned this Apr 24, 2026
@daniil-poletaev daniil-poletaev added the adhoc Ad-hoc unplanned task added during the sprint. label Apr 24, 2026
@github-actions github-actions Bot added t-unblocking Issues with this label are in the ownership of the unblocking team. tested Temporary label used only programatically for some analytics. labels Apr 24, 2026

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @daniil-poletaev !

Regarding the new separate option, I have another question. Are we planning to support passing multiple countries at some point? (e.g., "I want to scrape xyz.com either through Belgium or the Netherlands to make the proxy pool larger").

In such a case, separate country and subdivision code options would require us to change the API again, as we couldn't match the country and the subdivision code

countryCode: ['BE', 'NL'],
subdivisionCode: ['BRU', 'AMS'] // which country do these match?

Compare to the alternative countryCode: ["BE-BRU", "NL-AMS"], which disambiguates by default.

But, if we're positive that we don't want to go this way, it's a rather theoretical problem :)

Comment thread src/proxy_configuration.ts Outdated
const CHECK_ACCESS_REQUEST_TIMEOUT_MILLIS = 4_000;
const CHECK_ACCESS_MAX_ATTEMPTS = 2;
const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
const SUBDIVISION_CODE_REGEX = /^[A-Z0-9]{2}$/;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that, e.g., United Kingdom or Belgium do three-lettered codes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

Fixed it

Comment thread src/proxy_configuration.ts Outdated

if (subdivisionCodeToUse && !countryCodeToUse) {
throw new Error(
'"subdivisionCode" requires "countryCode" to be set.',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should make this even more explicit (e.g., mention ProxyConfiguration in the error message), so the user knows immediately where this comes from

@daniil-poletaev

Copy link
Copy Markdown
Contributor Author

Regarding the new separate option, I have another question. Are we planning to support passing multiple countries at some point? (e.g., "I want to scrape xyz.com either through Belgium or the Netherlands to make the proxy pool larger").

Maybe, but tbh it still would be a breaking change and we can change format later if it would be needed, so I would keep the format as-is for now 🤔

@daniil-poletaev daniil-poletaev requested a review from barjin April 27, 2026 08:54

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I don't have any further objections then :) (see small typo below)

Thank you @daniil-poletaev !

Comment thread src/proxy_configuration.ts Outdated
Comment on lines +68 to +69
* Same option as `subdivisionCode` which can be used to
* configurate the proxy by UI input schema. You should use the `subdivisionCode` option in your crawler code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Same option as `subdivisionCode` which can be used to
* configurate the proxy by UI input schema. You should use the `subdivisionCode` option in your crawler code.
* Same option as `subdivisionCode` which can be used to
* configure the proxy by UI input schema. You should use the `subdivisionCode` option in your crawler code.

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the last-minute note - can you also please make changes to https://docs.apify.com/sdk/js/docs/concepts/proxy-management , just like with the Python PR? Thanks!

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no further comments, thank you @daniil-poletaev !

@bliuchak bliuchak left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

const CHECK_ACCESS_REQUEST_TIMEOUT_MILLIS = 4_000;
const CHECK_ACCESS_MAX_ATTEMPTS = 2;
const COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
const SUBDIVISION_CODE_REGEX = /^[A-Z0-9]{1,3}$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would highly recommend add there a comment that explains that 1-3 range for an ISO standard that expects only 2 chars 😄

This was something that confused me.

@daniil-poletaev daniil-poletaev merged commit 3dcc38a into master Apr 28, 2026
9 checks passed
@daniil-poletaev daniil-poletaev deleted the feat/proxy-config-subdivision-code branch April 28, 2026 08:32
daniil-poletaev added a commit to apify/apify-sdk-python that referenced this pull request Apr 29, 2026
This PR adds new variable `subdivision_code` to Apify proxy
configuration. This variable is currently needed for US state targeting.

More context:
https://apify.slack.com/archives/C010Q0FBYG3/p1776704073278519

Same PR in JS: apify/apify-sdk-js#592
@bliuchak bliuchak added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-unblocking Issues with this label are in the ownership of the unblocking team. tested Temporary label used only programatically for some analytics. validated Issues that are resolved and their solutions fulfill the acceptance criteria.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants