---
title: "How to Submit Contact Us Data using GraphQL API in Magento 2"
url: "https://magecomp.com/blog/submit-contact-us-data-using-graphql-api-magento-2/"
date: "2023-10-20T11:39:54+00:00"
modified: "2025-02-12T12:31:23+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 654
reading_time: "4 min read"
summary: "Hello Magento Friends,"
description: "Learn the process of How to Submit Contact Us Data using GraphQL API in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How to Save Configuration Automatically when Extension is Installed"
    url: "https://magecomp.com/blog/magento-2-save-configuration-automatically-when-extension-installed/"
  - title: "Magento 2: Call Custom phtml file on all CMS Pages"
    url: "https://magecomp.com/blog/magento-2-call-custom-phtml-file-on-all-cms-pages/"
  - title: "Top 5 Magento Development Tools You&#8217;ll Need to Thrive in 2026"
    url: "https://magecomp.com/blog/top-magento-development-tools/"
---

# How to Submit Contact Us Data using GraphQL API in Magento 2

_Published: October 20, 2023_  
_Author: Dhiren Vasoya_  

![How to Submit Contact Us Data using GraphQL API in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/10/How-to-Submit-Contact-Us-Data-using-GraphQL-API-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In Magento 2, one of the most efficient tools for working with the platform is the GraphQL API. Using this feature, you can conveniently submit contact us data which will make it very convenient for your customers to pass across information to your business.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-3.webp)](https://magecomp.com/services/hire-magento-programmer/)

In this Magento 2 tutorial, we will guide you about How to Submit Contact Us Data using GraphQL API in Magento 2.
Let’s find out How to Submit Contact Us Data using GraphQL API in Magento 2.
## Steps to Submit Contact Us Data using GraphQL API in Magento 2:
**Step 1:** First, we need to create a **“schema.graphqls”** file inside the etc folder
**app\code\Vendor\Extension\etc\**

Then add the code as follows
```
type Mutation {
    contactusFormSubmit(input: ContactusInput!): Contactus @resolver(class: "\Vendor\Extension\Model\Resolver\Contactusgraphql") @doc(description:"Contact us form")
}

input ContactusInput {
    fullname: String @doc(description: "The customer's name")
    email: String @doc(description: "email address")
    telephone: String @doc(description: "The Telephone")
    message: String @doc(description: "message")
}

type Contactus {
    success_message: String @doc(description: "Success Message")
}
```

**Step 2:** After that, create the **“Contactusgraphql.php”** file inside the Resolver folder.
**app\code\Vendor\Extension\Model\Resolver\**

Now include the below-mentioned code
```
<?php
namespace VendorExtensionModelResolver;

use MagentoFrameworkExceptionNoSuchEntityException;
use MagentoFrameworkGraphQlConfigElementField;
use MagentoFrameworkGraphQlExceptionGraphQlInputException;
use MagentoFrameworkGraphQlExceptionGraphQlNoSuchEntityException;
use MagentoFrameworkGraphQlQueryResolverInterface;
use MagentoFrameworkGraphQlSchemaTypeResolveInfo;

class Contactusgraphql implements ResolverInterface
{
    private $contactusDataProvider;

    public function __construct(
        VendorExtensionModelResolverDataProviderContactus $contactusDataProvider
    ) {
        $this->contactusDataProvider = $contactusDataProvider;
    }

    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        $fullname = $args['input']['fullname'];
        $email = $args['input']['email'];
        $telephone = $args['input']['telephone'];
        $message = $args['input']['message'];

        $success_message = $this->contactusDataProvider->contactUs(
            $fullname,
            $email,
            $telephone,
            $message
        );
        return $success_message;
    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 3:** After that, we need to create the **“Contactus.php”** file inside the extension at the following path
**app\code\Vendor\Extension\Model\Resolver\DataProvider\**

And add the following code snippet
```
<?php
namespace VendorExtensionModelResolverDataProvider;

use MagentoFrameworkAppActionHttpPostActionInterface as HttpPostActionInterface;
use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;

class Contactus
{
    private $dataPersistor;
    private $mail;
    private $formKey;

    public function __construct(
        ConfigInterface $contactsConfig,
        MailInterface $mail,
        DataPersistorInterface $dataPersistor,
        MagentoFrameworkDataFormFormKey $formKey
    ) {
        $this->mail = $mail;
        $this->dataPersistor = $dataPersistor;
        $this->formKey = $formKey;
    }

    public function contactUs($fullname,$email,$subject,$message){
        $thanks_message = [];
        try {
            $this->sendEmail($fullname,$email,$subject,$message);
        }catch (LocalizedException $e) {
         }
        $thanks_message['success_message']="Thanks for contacting us with your comments and questions. We'll respond to you very soon.";
        return $thanks_message;
    }

    private function sendEmail($fullname,$email,$telephone,$message)
    {
        $form_data = [];
        $form_data['name']      =   $fullname;
        $form_data['email']     =   $email;
        $form_data['telephone'] =   $telephone;
        $form_data['comment']   =   $message;
        $form_data['hideit']    =   "";
        $form_data['form_key']  =   $this->getFormKey();

        $this->mail->send(
            $email,
            ['data' => new DataObject($form_data)]
        );
    }

    public function getFormKey()
    {
        return $this->formKey->getFormKey();
    }
}
```

**Step 4:** Run the upgrade command and compile command, and then pass the query like the below in the server
```
mutation{
    contactusFormSubmit(input:
    {
        fullname:"Test"
        email:"test.magecomp@gmail.com"
        telephone:"919664788894"
        message: "test-message"
    }){  success_message
  }}
```

**Output:**

![Submit Contact Us Data using GraphQL API in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/10/Submit-Contact-Us-Data-using-GraphQL-API-in-Magento-2.png)

## Conclusion:
By following the steps outlined in this guide, you can effectively leverage the Magento 2 GraphQL API to submit contact us data. This capability enables you to streamline the communication process and provide an enhanced user experience for your customers. Leveraging the power of GraphQL in Magento 2 allows for a more efficient and seamless data submission process.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-2.webp)](https://magecomp.com/magento-malware-removal.html)

If you face any difficulty in submitting contact us data using the GraphQL API, you can connect with me through the comment section. You can also [**Hire Magento Developer**](https://magecomp.com/hire-magento-developer.html) if you find difficulty working with GraphQL API.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/submit-contact-us-data-using-graphql-api-magento-2/](https://magecomp.com/blog/submit-contact-us-data-using-graphql-api-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-21 08:22:06 UTC_  
