//native
/**
* Create Contact
* Add a contact to the connected account's default contacts folder. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite (a connection default).
*/
export async function main(
auth: RT.MsOutlook,
given_name: string,
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", {
method: "POST",
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
/**
* Create Contact
* Add a contact to the connected account's default contacts folder. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite (a connection default).
*/
export async function main(
auth: RT.Outlook,
given_name: string,
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", {
method: "POST",
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
/**
* Create Contact
* Add a contact to the connected account's default contacts folder. `extra` takes any other contact property (e.g. `companyName`, `jobTitle`, `mobilePhone`). Requires Contacts.ReadWrite on the connection.
*/
export async function main(
auth: RT.Outlook,
given_name: string,
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", {
method: "POST",
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