//native
/**
* Update Contact
* Update a contact; only the fields you set are changed. `email_addresses` and `business_phones` replace the existing lists. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite (a connection default).
*/
export async function main(
auth: RT.MsOutlook,
contact_id: string,
given_name: string | undefined,
surname: string | undefined,
email_addresses: string[] | undefined,
business_phones: string[] | undefined,
extra: { [key: string]: any } | undefined
) {
const body: { [key: string]: any } = { ...(extra ?? {}) }
if (given_name != null && given_name !== "") body.givenName = given_name
if (surname != null && surname !== "") body.surname = surname
if (email_addresses?.length) {
body.emailAddresses = email_addresses.map((address) => ({ address }))
}
if (business_phones?.length) body.businessPhones = business_phones
const response = await fetch(
`https://graph.microsoft.com/v1.0/me/contacts/${encodeURIComponent(contact_id)}`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago
//native
/**
* Update Contact
* Update a contact; only the fields you set are changed. `email_addresses` and `business_phones` replace the existing lists. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite (a connection default).
*/
export async function main(
auth: RT.Outlook,
contact_id: string,
given_name: string | undefined,
surname: string | undefined,
email_addresses: string[] | undefined,
business_phones: string[] | undefined,
extra: { [key: string]: any } | undefined
) {
const body: { [key: string]: any } = { ...(extra ?? {}) }
if (given_name != null && given_name !== "") body.givenName = given_name
if (surname != null && surname !== "") body.surname = surname
if (email_addresses?.length) {
body.emailAddresses = email_addresses.map((address) => ({ address }))
}
if (business_phones?.length) body.businessPhones = business_phones
const response = await fetch(
`https://graph.microsoft.com/v1.0/me/contacts/${encodeURIComponent(contact_id)}`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 11 hours ago
//native
/**
* Update Contact
* Update a contact; only the fields you set are changed. `email_addresses` and `business_phones` replace the existing lists. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite on the connection.
*/
export async function main(
auth: RT.Outlook,
contact_id: string,
given_name: string | undefined,
surname: string | undefined,
email_addresses: string[] | undefined,
business_phones: string[] | undefined,
extra: { [key: string]: any } | undefined
) {
const body: { [key: string]: any } = { ...(extra ?? {}) }
if (given_name != null && given_name !== "") body.givenName = given_name
if (surname != null && surname !== "") body.surname = surname
if (email_addresses?.length) {
body.emailAddresses = email_addresses.map((address) => ({ address }))
}
if (business_phones?.length) body.businessPhones = business_phones
const response = await fetch(
`https://graph.microsoft.com/v1.0/me/contacts/${encodeURIComponent(contact_id)}`,
{
method: "PATCH",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 11 hours ago