Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

301 Unknown error #134

Closed
vcombey opened this issue Jan 24, 2023 · 5 comments · Fixed by #135
Closed

301 Unknown error #134

vcombey opened this issue Jan 24, 2023 · 5 comments · Fixed by #135

Comments

@vcombey
Copy link

vcombey commented Jan 24, 2023

    const client = new APIClient("********************************");
    try {
        const customers = await client.getCustomersByEmail(data.to);
    } catch (err: any) {
        console.log(err.statusCode, err.message)
    }

This code logs: 301 Unknown error

I'm using "customerio-node": "3.4.1",

I don't know what to do

@asplunds
Copy link

asplunds commented Feb 2, 2023

I'm getting this too. It seems the backend is trying to redirect to "https://beta-api-eu.customer.io" but the client is not following redirects. I believe this is an EU only issue.

if you log the full error you get:

body: '{"errors":[{"detail":"wrong datacenter","status":"301"}]}'

A workaround would be to use the REST api instead.

@asplunds
Copy link

asplunds commented Feb 2, 2023

Looking further it appears request.ts is using node https, this package has no built-in feature to follow redirects and does not follow redirects by default. You have to do it manually.

This is a pretty serious issue since if the backend wants to make a simple redirect, that could brick entire apps relying on cio. Please look into it.

@mike-engel
Copy link
Collaborator

Thanks for the info @asplunds, I have a PR ready with #135.

The real root cause here, however, is that you're not configuring the client to use the EU region (it defaults to the US). You should be creating the client like so:

const { APIClient, RegionEU } = require('customerio-node');

const client = new APIClient("********************************", { region: RegionEU });

Setting up the correct region avoids unnecessary redirects

@asplunds
Copy link

asplunds commented Feb 7, 2023

Thanks for the response @mike-engel, this was a mistake on my part I should've configured my client to use the EU region. I'm glad this was caught and being fixed however, since following redirects is still important regardless of region.

@mike-engel
Copy link
Collaborator

Fix released with 3.5.1. Thanks y'all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants