Set Proxy from API

  • Created

We recommend that you read the Getting started with Kameleo Automation article before reading this one.

In this article, we'll demonstrate how to set up and update a proxy for a Kameleo profile using the Local API Clients. Setting up a proxy allows you to route your browsing traffic through a designated proxy server, which can be useful for various web-scraping or browser automation tasks. We have a separate article about why you need to use a good residential proxy to have the best protection while you are using Kameleo, and we also have an article if you are not familiar with the proxy providers:

Concept

When creating a new profile via the Kameleo Local API, you can specify a proxy configuration using the Proxy method. This method accepts the following proxy types:

  • HTTP
  • SOCKS5
  • SSH

Furthermore, once you select your desired proxy type, you also need to fill in the follow-up information on the proxy details such as Host, Port, Username, and Password.

With the built-in proxy manager, you can easily integrate any proxy provider with Kameleo even through the Local API.

Setting a Proxy During Profile Creation

  • @type {import('@kameleo/local-api-client').CreateProfileRequest} */
    const createProfileRequest = {
        fingerprintId: fingerprints[0].id,
        name: "start with proxy example",
        proxy: {
            value: "socks5",
            extra: {
                host: process.env["PROXY_HOST"] || "",
                port: Number(process.env["PROXY_PORT"]) || 1080,
                id: process.env["PROXY_USERNAME"] || "",
                secret: process.env["PROXY_PASSWORD"] || "",
            },
        },
    };
    const profile = await client.profile.createProfile(createProfileRequest);
  • var createProfileRequest = new CreateProfileRequest(fingerprints[0].Id)
    {
        Name = "start with proxy example",
        Proxy = new (ProxyConnectionType.Socks5, new Server(proxyHost, proxyPort, proxyUsername, proxyPassword))
    };
    
    var profile = await client.Profile.CreateProfileAsync(createProfileRequest);
  • create_profile_request = CreateProfileRequest(
        fingerprint_id=fingerprints[0].id,
        name='start with proxy example',
        proxy=ProxyChoice(
            value='socks5',
            extra=Server(host=PROXY_HOST, port=PROXY_PORT, id=PROXY_USERNAME, secret=PROXY_PASSWORD)
        ))
    profile = client.profile.create_profile(create_profile_request)

Updating Proxy Settings for an Existing Profile

If you want to update the proxy settings of an existing profile instead of creating a new one, follow this example:

  • from kameleo.local_api_client import KameleoLocalApiClient
    from kameleo.local_api_client.models import UpdateProfileRequest, ProxyChoice, Server
    
    # Create the client
    client = KameleoLocalApiClient()
    
    # Example profile ID
    profile_id = 'your-profile-id-here'  # Replace with actual ID
    
    # New proxy settings
    update_request = UpdateProfileRequest(
        proxy=ProxyChoice(
            value='socks5',
            extra=Server(host='new-host.com', port=1080, id='user', secret='pass')
        )
    )
    
    client.profile.update_profile(profile_id, update_request)

Make sure to replace the placeholders (<host>, <port>, <user>, <pass>) with the actual values of your proxy server.

In the CLI you will be notified with a message resembling this one:
[00:00:00] [INF] Profile with id 551132c0-e2f3-4e9d-ade8-3d4267b1e8f1 has been updated in local storage.

For more details, refer to the following example code repository:

If you need additional assistance, or if you have any questions please open a ticket via the Contact Support page.

Was this article helpful?

0 out of 0 found this helpful