I am trying to get an access token from Instagram API. I'm want to send the body as form-data. This is my code. this is not working. but it works fine in postman.
async getAccessTokenByCode(code: string): Promise<string> {
const baseUrl = config.get('authorize.baseUrl');
const clientId = config.get('basic.clientId');
const clientSecret = config.get('basic.clientSecret');
const grantType = config.get('basic.grant_type');
const redirectUri = config.get('basic.redirect_uri');
const url = `${baseUrl}/oauth/access_token`
const form = new FormData();
form.append('client_id', clientId);
form.append('client_secret', clientSecret);
form.append('grant_type', grantType);
form.append('redirect_uri', redirectUri);
form.append('code', code);
try {
const response = await this.httpService.post(url, { data: form }, { headers: form.getHeaders() }).toPromise();
return response.data;
} catch (error) {
console.log(error);
}
}
How to properly send post data using NestJS HttpModule??