Answer the question
In order to leave comments, you need to log in
How to pass offline conversion to node js request?
Guys tell me how to transfer the csv file using node js and request as required by yandex.
Everything works in php and curl, but here I can't get it to work.
Documentation yandex
https://yandex.ru/dev/metrika/doc/api2/practice/of...
// requestSend
async function requestSend(data) {
// errorMsg
var errorMsg = {result: false};
// errorData
if (!data && !data.paramData) {
return errorMsg;
};
var data = data.paramData;
// request options
let requestOptions = {
url: data.url,
method: data.method,
headers: {
'Authorization': 'OAuth '+global.config.settings.YandexMetrikaKey,
'Content-Type': 'multipart/form-data',
},
};
async function yandexResponse(data) {
return new Promise(resolve => {
request(data, (err, res, responseBody) => {
console.log(err)
console.log(res)
console.log(responseBody)
if (!err && res.statusCode == 200) {
resolve(responseBody)
}
})
})
}
const requestResponse = await yandexResponse(requestOptions);
console.log(requestResponse)
if (requestResponse && requestResponse !== 'undefined') {
return {result: true, resultData: requestResponse};
}
return errorMsg;
}
{
url: 'https://api-metrika.yandex.net/management/v1/counter/НомерСчетчика/offline_conversions/upload?client_id_type=CLIENT_ID',
file: 'полный_путь_к_файлу_csv.csv',
fileName: 'название_файла.csv',
method: 'POST'
}
{"errors":[{"error_type":"invalid_uploading","message":"Request parameter not found","location":"file"}],"code":400,"message":"Request parameter not found"}
Answer the question
In order to leave comments, you need to log in
Is the file coming from the frontend? Or are you sending from a computer?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question