APIs & Integrations

ArminK
Member

Update Secondary Email v3 API

Hello,

I am currently migrating out hub spot integration to the new API. I have created an app, and replaced the old nodejs module with the new that you have provided on your api page. I replaced some of or logic that writes contacts into hubspot.

However, I cannot find any way to add or update the secondary mail of our contacts over the new API. 

I searched the documentation but could not find anything about it.

Can I still use the v1 endpoint without the nodejs package ?
Will it also be shut down, or will it stay after the 30th november 2022?
If yes, how to retrieve the secondary email over the nodejs package? What property name to use?

I hope you will be able to help us
Thanks


0 Upvotes
2 Replies 2
Jaycee_Lewis
Community Manager
Community Manager

Update Secondary Email v3 API

Hey, @ArminK 👋 Quick questions to help the community better understand what you've already tried. 

  • Specifically, which endpoints are you currently using?
  • Is it one of the Secondary Endpoints listed here? Developer Preview — Secondary Email Addresses
  • For adding, updating, and deleting a secondary email address, the above endpoints are the current option
  • If you only need to get the secondary email addresses, you can use 
     the hs_additional_emails property ​
    to list the primary and secondary addresses in other calls to the Contact endpoints

    Quick example (I used cURL, but the NodeJS example works as well)
    Endpoint 
    GET/crm/v3/objects/contacts/{contactId}​
    Request
    curl --request GET \
      --url 'https://api.hubapi.com/crm/v3/objects/contacts/551?properties=hs_additional_emails&archived=false' \
      --header 'authorization: Bearer YOUR_ACCESS_TOKEN'​

    Response

    HTTP 200
    
    {
      "id": "551",
      "properties": {
        "createdate": "2022-08-11T23:27:36.511Z",
        "hs_additional_emails": "ihatethefood@cat.com;younewcatboss@cat.com",
        "hs_object_id": "551",
        "lastmodifieddate": "2022-08-15T20:37:13.785Z"
      },
      "createdAt": "2022-08-11T23:27:36.511Z",
      "updatedAt": "2022-08-15T20:37:13.785Z",
      "archived": false
    }

The Developer Preview — Secondary Email Addresses endpoints already work with OAuth and Private Apps. Please be aware these endpoints are all part of the developer preview program and are subject to the following:

This endpoint is part of our developer preview program, and should be considered as a non-stable release that will be subject to bugs and breaking changes while under development. Please take this into account as you build against a release. Please subscribe to our changelog for updates.

 

Best,

Jaycee

 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

ArminK
Member

Update Secondary Email v3 API

Hello,

 

thank you for your help. I managed to get it working.

In the old integration with api keys, we used the nodejs package hubspot 2.3.14. This package has a method add a secondary mail, so i could go with:

import Hubspot from 'hubspot';

export const updateContactSecondaryMail = async (
  hubspot: Hubspot,
  contactMail: string,
  secondMail: string
) => {
  const { vid } = await hubspot.contacts.getByEmail(contactMail);
  return hubspot.contacts.addSecondaryEmail(vid, secondMail);
};

 

But the new node package @hubspot/api-client does not have this property. So I wanted to know if I can use the API endpoint from the Developer Preview — Secondary Email Addresses endpoints, and if it is usable with OAuth.

It would be nice if the new node package would have a method to add a secondary email address or something similar. I now had to use axios:

import { Client } from '@hubspot/api-client';
import Axios from 'axios';

export const addSecondaryMail = async (
  client: Client,
  contactId: string,
  secondaryEmail: string
) => {
  const axios = Axios.create({
    baseURL: 'https://api.hubapi.com/contacts/v1/secondary-email/',
    headers: {
      Authorization: `Bearer ${client.config.accessToken}`,
      'Content-Type': 'application/json',
    },
  });

  return axios.put(
      `/${contactId}/email/${encodeURIComponent(secondaryEmail)}`
    );
};


I now just wanted to know will this solution work after you shut down the api key authentification method on 30 november 2022 ?

Thanks