customerio / customerio-node Goto Github PK
View Code? Open in Web Editor NEWA node.js client for the Customer.io REST API.
Home Page: https://customer.io/docs/api/
License: MIT License
A node.js client for the Customer.io REST API.
Home Page: https://customer.io/docs/api/
License: MIT License
I should be able to do the following in my application:
cio.trackEvent({
customer_id: 20,
event: "some_event",
data: {}
})
Is there a timeline for adding the missing parameters for a triggered broadcast?
ids
id_ignore_missing
emails
email_ignore_missing
email_add_duplicates
Thanks!
I should be able to do the following in my application:
cio.deleteCustomer(20);
Where 20 is the Customer ID.
I should be able to do this in my application:
cio.createUser({});
https://customer.io/docs/push-developer-guide/#step-4-send-events-for-key-customer-actions
The document use URL https://track.customer.io/push/events
to send when the push notifications have been opened.
Please kindly advise how to use this lib to achieve the function.
I'm following your documentation for tracking events in Node.js. I'm running into an issue where I keep getting
[ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
Here's my sample code:
const userId = 'adajkdaAS7aAS';
const customerioTrackClient = new TrackClient(
'mySiteId',
'myApiKey',
{ region: RegionUS }
);
await customerioTrackClient.track(userId, {
name: 'ExampleName',
data: {
sku: 'blahlah',
},
});
Any ideas?
Hi there, I observed that the manual segment APIs addToSegment
and removeFromSegment
were removed in this commit and no longer exists in the v1.0.0 release: e487c3c
Is there any reason why these APIs were removed? We currently make use of these APIs.
When triggering a broadcast with per_user_data
or data_file_url
, we should be able to pass in additional options like we currently do for ids & emails:
Lines 5 to 10 in 98a17a2
I think this should become
const BROADCASTS_ALLOWED_RECIPIENT_FIELDS = {
ids: ['ids', 'id_ignore_missing'],
emails: ['emails', 'email_ignore_missing', 'email_add_duplicates'],
per_user_data: ['per_user_data', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates'],
data_file_url: ['data_file_url', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates']
}
relevant customer.io docs: https://customer.io/docs/api/#apicorecampaignscampaigns_trigger
Is there any way to get the Subscription Center topics?
When using cio_id
to update a person, the id must be used with cio_
as a prefix. While this is outlined in the API documentation here, it would also be helpful to include this detail in the node readme file on cio.identify (or link to the API documentation) to help eliminate any confusion for people seeking to use the cio_id to update profiles.
HS ticket: https://secure.helpscout.net/conversation/1604941123/132227
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
We are experiencing errors when sending emails in broadcast mode after identifying a user, the identify endpoint responds 200 but when we send broadcast emails with ids option the recipients remain at 0, there must be a data synchronization issue between their 2 services (broadcast / identity.... you recently moved this endpoint).
As a workaround we have to fail with the flag ({id_ignore_missing:false} RECIPIENTS_ERROR_CODE (422)
) if any of our recipients are missing in your side and we've built a cron job server to retry the failed broadcasts
Is there or will there be support for the bulk api/api v2? Thanks!
Hi, I've been meaning to send data from my Node.js app to Customer.io, and stumbled upon this official package. The API looks complete, but it lacks traction compared to other unofficial libraries (such as node-customerio or node-customer.io).
Will this library be supported in the long run if I decided to use this in production or should I use the other libraries?
I was wondering how to get the equivalent of calling https://track.customer.io/api/v1/customers/${userId}/attributes
using this library. https://www.customer.io/docs/api/#operation/getPersonAttributes shows an example with the plain https module, but that seems a little silly if there's an API package available? =)
Hi!
How to use typings of customerio-node
?
thanks!
As subject states, this is about email sending. Would be great to indicate how to pass the email to cio, and not leave it to our guessing :)
thanks
We are using transactional_message_id
in SendEmailRequest
to specify a message template, but we need to be able to override the subject
.
Per the Customer.io docs,
If you include both a
transactional_message_id
and asubject
, thesubject
in your request overwrites the values in your message template.
However this does not work with this library; this code is the culprit:
if ('from' in opts) {
this.message.from = opts.from;
this.message.subject = opts.subject;
this.message.body = opts.body;
}
Can you please set subject
regardless?
This is a showstopper for us; we need to be able to set the email subject line to different values (but still use a template).
Great work on the library. How do I increment the value of a property on a person? For example:
cio.identify(1, {
email: '[email protected]',
created_at: 1361205308,
first_name: 'Bob',
plan: 'basic',
number_of_purchases: 0
});
Each time a user makes a purchase, I want to increment number_of_purchases
by 1, so I don't have to write a database query to count all the purchases a user has made. Thank you.
cc: @mike-engel
A lot of endpoints are missing, hence the question.
Could you archive the repository if that's not the case?
Hi there,
We got a message from CustomerIO to use Bearer Auth instead of Basic Auth when using API.
Hi there,
We've noticed that you've used basic authentication to access the App API in the last 30 days. You will need to change the authentication method within the next 2 weeks, or calls to send triggered broadcasts or transactional messages will fail.
Beginning April 14th at 00:00 UTC we will no longer allow access to our App API through basic authentication. Instead, bearer authentication is required to utilize the API. You can find more details on this authentication scheme in our API documentation.
If you have any questions, simply reply to this email and we'll be happy to help!
Thanks!
CIO Engineering Team
Can you please make TrackClient
to support Bearer Auth as well? Currently it supports only Basic Auth.
if i use cio.identify in a wrong way (cio.identify(object)) it have to reject the promise
I should be able to do the following in my application:
cio.updateCustomer({});
Hi folks,
We have a use case where we want to send events from the front-end instead of the backend, and this node SDK doesn't work because it uses some node-specific libraries such as fs
.
So I've copied this repo and made it compatible with frontends: https://github.com/stefanoeb/react-native-customerio
It probably works with web as well, but I've just tested on react-native for now.
This is just an FYI for anyone trying to send stuff from the frontend as well in the future.
Hi there!
I'm a user of the customer.io-node library and I've been really impressed with how easy it is to send targeted emails and messages to my customers. However, I've noticed that the library doesn't currently support interacting with Customer.io's objects feature, which was recently added to the platform (https://customer.io/docs/objects/#).
I believe that adding support for objects would be a valuable addition to the customer.io-node library because it would allow users to take advantage of this powerful new feature. By using objects, we can associate data with our customers and create more personalized messaging experiences based on their attributes.
Specifically, I'd like to request that the customer.io-node library add methods for creating, updating, and deleting objects. Ideally, these methods would be easy to use and would integrate seamlessly with the existing functionality of the library.
I think that adding support for objects would make customer.io-node an even more valuable tool for marketers and businesses looking to connect with their customers in more meaningful ways.
Thanks for considering my request!
When calling the identify
method (I'm using the last version "0.7.0" of your lib), and in the case where a 400 error happened because of a too long attribute value, here is what I get :
message: 'Unknown error',
statusCode: 400,
...
body: '{\n' +
' "meta": {\n' +
' "errors": [\n' +
` "value for attribute 'myAttribute' cannot be longer than 1000 bytes"\n` +
' ]\n' +
' }\n' +
'}\n',
After a look into your code, I noticed that this specific line :
customerio-node/lib/request.js
Line 48 in 52e27c2
meta {
error // string
}
Whereas I'm getting this :
meta {
errors // array of string
}
Is it something that you are planning to deal with at some point ? For now, I handled it myself but it would be nice to include it in the lib I guess :)
I am getting the following error, while trying to use the package:
error TS2345: Argument of type 'null' is not assignable to parameter of type 'Record<string, any> | PromiseLike<Record<string, any>>'
It happens when the project is compiled as part of NestJs applciation.
Basically, it says that json
has a wrong type, which was deducted from value assigned to it (an it is only null
). While function response never expects null
as return type.
Can you modify it to something like: resolve(json ?? {});
?
npm package "request" has been deprecated and contains references to a vulnerable version of ajv. Removal of this package will remove this vulnerability within customerio-node package.
I need to be able to create a segment and add users to it.
We're bundling our backend with Rollup before uploading to Lambda, and this line of code inside lib/request.ts
just made our Lambda hang, because of some infinite loop caused by Rollup + this particular piece of code. It happens when it can't find a package.json
(and because everything is bundled, there is no package.json
uploaded to AWS Lambda.)
const PACKAGE_JSON = findPackageJson(resolve(__dirname, '..'));
Could this be turned into something that also works inside bundled files?
e.g.:
let PACKAGE_JSON: any;
try {
PACKAGE_JSON = require('../package.json');
} catch (e) {}
I am writing to request documentation or guidance on how to properly send Base64 attachments via email. I am encountering difficulties when attempting to include Base64-encoded attachments in the Transactional API.
The web documentation specifies that is possible (https://customer.io/docs/journeys/email-attachments/), but it's not clear how to do it from this library.
Found this issue on transaction API where by default the value for fake_bcc is true
and due to this, it leads to parent recipient's name + email is appended to the subject.
When trying to disable this option and following the error encountered with the library, whereas it works fine on the API side.
CustomerIORequestError: Request entity must be JSON encoded and not exceed 3024 KB.
fake_bcc
should be a boolean as on the API and seem to be the cause of this issue, when types are overwritten and we pass a boolean value for fake_bcc
things work fine on API as well as with CURL.
Please suggest if any additional updates would be required, adding an issue for tracking.
Will send a fix soon.
In the README, it has this sample code:
let cio = new TrackClient(siteId, apiKey, { region: RegionUS }, [defaults]);
The [defaults]
argument is incorrect; the signature is (siteid: string, apikey: string, defaults?: Partial<TrackDefaults> | undefined)
.
This example is also incorrect in TypeScript:
const cio = new TrackClient(123, 'abc', {
timeout: 5000
});
siteId
(123) should be a string.
The API should have Beta methods, specially GET /customers
.
Is it OK to create a PR for it?
I think it's an API issue but when I send special characters as message data it returns "Request entity must be JSON encoded and not exceed 2548 KB.". When I replace the special characters with ä everything works. Now have to write a helper function to parse the json object for those characters and replace them.
To reproduce:
const request = new SendEmailRequest({
to: <your email>,
transactional_message_id: <message id>,
message_data: {
name: "Stämpfli", // "Stämpfli" works here..
},
identifiers: {
id: <customer id>,
},
});
const apiClient = new APIClient(<api key>);
return apiClient.sendEmail(request);
I am using version 3.0.1
When using customer-io in development we don't pass a correct key.
So the calls return an Unauthorized request
But request.js
tries to parse the string like this JSON.parse(body)
and throws this error:
(node:34878) UnhandledPromiseRejectionWarning: Error: Unable to parse JSON. Error: SyntaxError: Unexpected token U in JSON at position 0
Body:
Unauthorized request
at IncomingMessage.<anonymous> (/xxx/node_modules/customerio-node/dist/lib/request.js:48:39)
at IncomingMessage.emit (events.js:326:22)
at IncomingMessage.EventEmitter.emit (domain.js:483:12)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
This project relies on the native "http" / "https" modules from Node.js which are not compatible on Edge environments such as Cloudflare Workers, Next.js Edge Routes / middleware nor AWS Lambda Edge.
I would recommend a version built on top of "fetch" witch is getting a native Node.js implementation.
See: #124
When calling getCustomersByEmail("[email protected]")
the query parameters are not being passed along. So, as a result, the GET request URL is /v1/customers
instead of /v1/[email protected]
.
I should be able to do something like this in my application:
cio.createCustomer({}).then(function(){
// success
}, function(){
// failure
});
Hi, I was wondering if there's support for the Track V2 API, more specifically https://track.customer.io/api/v2/batch
. If not, is there any workaround that we could use to send data through batch calls for identify
and destroy
functions?
Is there a way to use the destroy()
method by passing in an email address instead of their cio_id
?
Ensure that Unicode characters (i.e. umlauts) are supported when going to the api
Feature request: Download a customer export. I'd like to automate a report that joins CIO customer table with an external system and the exports API looks to be helpful. It'd be great if this SDK supported this as a single method (and I imagine a similar method for exporting deliveries would be welcome too).
Auto-generated documentation is better than human generated documentation, so let's try and make an effort to publish online docs with typedoc!
We have come across an issue where the customer.io client fails to send notifications when quotes are included in the payload.
For example, when sending a payload like this:
const trackClient = new TrackClient(
process.env.CUSTOMERIO_SITE_ID,
process.env.CUSTOMERIO_API_KEY
);
trackClient.track('some_user_id', {
name: 'notify',
data: {
'title': 'My Title "Just Will Not Work" With Quotes Included',
},
});
The notification will result in an "attempted" status with reason:
Custom payload is invalid JSON: invalid character 'J' after object key:value pair
I believe this is due to the quotes not being escaped by the client before the request is sent.
We are applying a fix for this prior to client use by escaping the quotes before the track
call. But I wanted to flag this as a potential feature to add so others aren't caught by the same issue.
Hi, not sure where is the best place to post this.
There is an important detail missing from the transactional messages docs for one parameter.
https://customer.io/docs/api/#operation/sendEmail
send_at
A unix timestamp determining when the message will be sent. The timestamp can be up to 90 days in the future. If this value is in the past your message is sent immediately.
The timestamp should be in seconds!
Not milliseconds (which new Date().getTime()
or Date.now()
returns)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.