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

Add extra device data to attributes object in addDevice #115

Merged

Conversation

xanderberkein
Copy link
Contributor

To add extra data to a device, we should use the attributes param in the add/update device API call (see the official docs)

Currently, extra data gets spread out over the request params and it doesn't arrive in customer.io.

This PR makes sure that data that's passed along through the data param in the addDevice function, is properly sent to the API by putting it in the required attributes param.

@xanderberkein xanderberkein changed the title Add extra device data to attributes object inaddDevice Add extra device data to attributes object in addDevice Sep 9, 2022
lib/track.ts Outdated
@@ -116,7 +116,7 @@ export class TrackClient {
}

return this.request.put(`${this.trackRoot}/customers/${encodeURIComponent(customerId)}/devices`, {
device: { id: device_id, platform, ...data },
device: { id: device_id, platform, attributes: { ...data } },
Copy link
Collaborator

Choose a reason for hiding this comment

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

While you're here @xanderberkein, let's add support for last_used here:

Suggested change
device: { id: device_id, platform, attributes: { ...data } },
let { last_used, ...attributes } = data;
device: { id: device_id, platform, last_used, attributes },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mike-engel added in my latest commit

mike-engel
mike-engel previously approved these changes Sep 15, 2022
Copy link
Collaborator

@mike-engel mike-engel left a comment

Choose a reason for hiding this comment

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

Thanks @xanderberkein!

@xanderberkein
Copy link
Contributor Author

@mike-engel I've made it so that last_used and attributes only get sent when defined. This fixes the failing test.

@mike-engel mike-engel merged commit fbcd5db into customerio:main Sep 16, 2022
@mike-engel
Copy link
Collaborator

Thanks @xanderberkein, this should be available in 3.3.5 now

@xanderberkein xanderberkein deleted the add-addDevice-data-to-attributes-obj branch September 16, 2022 07:56
@xanderberkein
Copy link
Contributor Author

Great, thanks!

@xanderberkein
Copy link
Contributor Author

xanderberkein commented Sep 16, 2022

@mike-engel It seems like you didn't include the build (dist directory) in the 3.3.5 release.

@mike-engel
Copy link
Collaborator

Hmm, looks like npm doesn't run the prepublish script anymore. I'll publish a new version shortly, thanks for bringing this up

@mike-engel
Copy link
Collaborator

Should be fixed in 3.3.6 now, thanks @xanderberkein

@xanderberkein
Copy link
Contributor Author

@mike-engel Works now, thanks!

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 this pull request may close these issues.

2 participants