---
title: Attach Contact
slug: netsuite/attach-contact
description: Learn how to attach an existing contact record as the primary contact to a sales order or customer in the NetSuite system using code snippets in Apex language. This document provides step-by-step examples, guiding you through initializing data, creating a
docTags: 
createdAt: 2023-05-05T09:50:11.000Z
---

NetSuite Contact can be attached as a Primary Contact to Transaction and other records in NetSuite.&#x20;

Example to attach an existing Contact record as primary contact to a Sales Order:

:::CodeblockTabs
Request

```apex

Map<String, Object> nsAttachReference = new Map<String, Object>();
nsAttachReference.put('attachTo', new Map<String, Object>{'internalId'=>'120956','type'=>'salesOrder'});
nsAttachReference.put('contact', new Map<String, Object>{'internalId'=>'15959'});

Map<String, Object> nsAttachment = new Map<String, Object>();
nsAttachment.put('attachReference',nsAttachReference);
   
//  Initialize the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('attachContacts', new List<Object>{nsAttachment});
String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'attachContact');
reqObj.put('requestJSON', reqJSON);

//  Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```
:::

Example to attach an existing Contact record as primary contact to a Customer:

:::CodeblockTabs
Request

```apex

Map<String, Object> nsAttachReference = new Map<String, Object>();
nsAttachReference.put('attachTo', new Map<String, Object>{'internalId'=>'10341','type'=>'customer'});
nsAttachReference.put('contact', new Map<String, Object>{'internalId'=>'15959'});

Map<String, Object> nsAttachment = new Map<String, Object>();
nsAttachment.put('attachReference',nsAttachReference);
   
//  Initialize the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('attachContacts', new List<Object>{nsAttachment});
String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'attachContact');
reqObj.put('requestJSON', reqJSON);

//  Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```
:::

