> For the complete documentation index, see [llms.txt](https://signtogether.gitbook.io/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://signtogether.gitbook.io/api-docs/api-2.md).

# API 더 알아보기

## 1. 서명 화면을 팝업으로 열기

```javascript
const signingUrl = '계약 문서 생성 API 로 받은 signingUrl';
const newWindow = window.open(signingUrl, '_blank');

window.addEventListener('message',(event) =>{
    if(event.data.action === 'closeWindow'){
        this.newWindow.close();
    }
    if(event.data.result === 'signed'){
        /* 이 부분에서 완료 파일 다운로드 페이지를 호출하거나
        완료 문서 + 참고 파일 문서를 생성하는 API 호출합니다. */
    }
});
    
```

1. 서명 화면을 브라우저의 새 창 새 탭으로 오픈 합니다.

2. 서명 화면에서 완료 버튼을 눌러 계약을 완료하면 발생하는 ‘message’ 이벤트에 대해서 반응할 수 있도록 합니다 (본 Listener 는 중복 처리되지 않도록 하세요.

3. 이벤트의 action이 'closeWindow' 인 경우에는 팝업을 닫는 코드를 호출하여 팝업을 닫습니다.

4. 이벤트의 result 가 'signed' 인 경우 계약이 완료된 것입니다 완료에 대한 후속 처리를 진행하면 됩니다

## 2. 다운로드를 위한 처리

{% hint style="info" %}
아래의코드와 같은 프로세스를 처리하는 화면 또는 함수를 만들어 사용하세요.
{% endhint %}

```javascript
axios.post('https://{API_URL}/rest/api/get-download-url',
{
    sharedKey:공유키, 
    downloadFileType: 'C',
},
{
    headers: {
        'Content-Type': 'application/json', 'apikey': 'API에 대한 인증키'
    }
})
.then(response => {
    const { data } = response; 
    const fileUrl = data.pdfUrl;
    
    // <a> 태그를 동적으로 생성하고 파일 다운로드 링크로 사용
    const link = document.createElement('a'); link.href = fileUrl;
    link.target = '_blank'; // 새 창에서 열릴지 설정 (필요에 따라 변경) 
    document.body.appendChild(link);

    link.click();  // 링크를 클릭하여 파일 다운로드 실행
    document.body.removeChild(link); // 링크를 삭제하여 메모리 누수 방지

    // (optinal) 파일 다운로드 페이지를 별도로 만든 경우 해당 창을 닫음.
    window.self.close();
    })

.catch(error => {
// 에러 처리
});

```

1. get-download-url API 을 호출하여 다운로드 URL을 획득합니다.

2. 문서 생성 시 획득한 공유키와 다운로드할 파일 타입을 전달하여 주세요

* **C (composite)** : 완료 문서 + 참고 파일 PDF
* **D (default)** : 완료 문서 PDF

3. 성공 응답이 오면 pdfUrl 을 이용하여 줍니다.

4. a 태그를 이용하여 파일을 다운로드합니다.

5. 파일 다운로드를 위한 화면을 따로 만들었다면 해당 화면을 닫아 줍니다.
