Skip to content

Contact Form API

Feature name: contact-form

Api name: ContactFormApi


API used to send a contact form without the need to use a contact-form webcomponent.

classDiagram
direction LR
    ContactFormApi --> submit

    class ContactFormApi {
        submit(submitContactFormProps: TSubmitContactFormProps) Promise~TResponseStatus|undefined~
    }

    ContactFormApi : TResponseStatus 'success' | 'failed' | undefined

    link submit "../methods/submit/"

Get API

To get the Contact Form API use its name ContactFormApi with the getApi method.

useStorefront(async (storefront) => {
    const contactFormApi = storefront.getApiSync('ContactFormApi');
});

This API is initialized only after contact-form webcomponent has been added to the page. Unless you add the webcomponent, you won't be able to fetch the API. If you wish to use the API alone without the webcomponent you can use the registerDynamic method from the Feature System API. Here is an example on how to do it:

useStorefront(async (storefront) => {
    const featureSystemApi = this.getApiSync('FeatureSystemApi');
    await featureSystemApi.registerDynamic('contact-form');

    const contactFormApi = storefront.getApiSync('ContactFormApi');
});

Methods

  • submit - submit a contact form via api

Examples

Making a Contact Form API call to send a message.

    useStorefront(async (storefront) => {
        const contactFormApi = storefront.getApiSync('ContactFormApi');

        await contactFormApi.submit({
            name: 'John Snow',
            email: 'email@example.com',
            subject: 'Example subject',
            content: `Example content`,
            additional_1: '45',
            additional_2: 'yes'
        });
    });

Webcomponents reference

Objects Reference

APIs reference