봄날은 갔다. 이제 그 정신으로 공부하자

[POSTMAN] Pre-request 스크립트를 사용해 API 호출 전처리 작업하기 본문

카테고리 없음

[POSTMAN] Pre-request 스크립트를 사용해 API 호출 전처리 작업하기

길재의 그 정신으로 공부하자 2025. 2. 5. 10:10
pm.sendRequest({
    url: "https://" + pm.collectionVariables.get("host") + pm.collectionVariables.get("loginUrl"),
    method: 'POST',
    header: {
        'Accept': 'application/json',
        'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: {
        mode: 'urlencoded',
        urlencoded: [
        {
            key: "id", 
            value: pm.collectionVariables.get("id"), 
            disabled: false
        },
        {
            key: "pwd", 
            value: pm.collectionVariables.get("pwd"), 
            disabled: false
        }
        ]
    }
}, function (err, res) {
    let res_data = res.json();    
    // 로그인 결과값 환경 변수에 저장
    pm.collectionVariables.set("accessToken", res_data.data.access_token);
    pm.collectionVariables.set("refreshToken", res_data.data.refresh_token);
}
);
Comments