How to use the post function from axios

Find comprehensive JavaScript axios.post code examples handpicked from public code repositorys.

14
15
16
17
18
19
20
21
22
23
}

async postToSlack({ message }) {
  try {
    if (!this.slackUrl) return
    await axios.post(this.slackUrl, { text: message })
  } catch (e) {
    this.childLogger.info(
      `Error posting to slack in slack reporter ${e.toString()}`
    )
fork icon99
star icon491
watch icon26

1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
    },
  ],
};

try {
  const quoteResponse = await axios.post("https://bot.lyo.su/quote/generate", quoteJson, {
    headers: { "Content-Type": "application/json" },
  });

  const buffer = Buffer.from(quoteResponse.data.result.image, "base64");
fork icon628
star icon36
watch icon2

+ 4 other calls in file

9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
// eslint-disable-next-line no-await-in-loop
const signature = await signCheckAppData(stringData);
data.signature = signature;
// first check against our IP address
// eslint-disable-next-line no-await-in-loop
const resMyAppAvailability = await axios.post(`http://${askingIP}:${askingIpPort}/flux/checkappavailability`, JSON.stringify(data), axiosConfig).catch((error) => {
  log.error(`${askingIP} for app availability is not reachable`);
  log.error(error);
});
if (resMyAppAvailability && resMyAppAvailability.data.status === 'error') {
fork icon227
star icon164
watch icon24

13
14
15
16
17
18
19
20
21
22
    Authorization: AuthStr,
  },
};

try {
  const installGoalPlugin = await axios.post(config.url, config.data, { headers: config.headers });

  const { data: response } = installGoalPlugin;

  return response.data;
fork icon68
star icon17
watch icon3

61
62
63
64
65
66
67
68
69
70

async post(url, body, headers, config = {}) {
        config.headers = headers;
        config = this._checkConfig(config);
        // axios serialize json data
        return axios.post(url, body, config)
}

async put(url, body, headers, config = {}) {
        config.headers = headers;
fork icon51
star icon418
watch icon30

46
47
48
49
50
51
52
53
54
55
this.service = 'capmonster';
this.key = key;
this.solve = async (captchaData, userAgent) => {
  // https://github.com/aiko-chan-ai/discord.js-selfbot-v13/issues/548#issuecomment-1452091328
  try {
    const createTaskResponse = await axios.post('https://api.capmonster.cloud/createTask', {
      clientKey: this.key,
      task: {
        type: 'HCaptchaTask',
        websiteURL: 'https://discord.com/channels/@me',
fork icon61
star icon285
watch icon9

+ 9 other calls in file

175
176
177
178
179
180
181
182
183
184
  }
  const data = {
    device_mac: deviceMac,
    device_model: deviceModel,
  }
  result = await axios.post(`${this.baseUrl}/app/v2/device/get_device_info`, await this.getRequestBodyData(data))
} catch (e) {
  throw e
}
return result.data.data
fork icon20
star icon162
watch icon23

+ 11 other calls in file

303
304
305
306
307
308
309
310
311
312
const url = baseEndpoint + category.createOrUpdateUserEndpoint;
const config = { headers };
const payload = { user: userObject };

try {
  const resp = await axios.post(url, payload, config);

  if (!resp.data || !resp.data.user || !resp.data.user.id) {
    logger.debug(`${NAME}:: Couldn't create User: ${name}`);
    throw new NetworkInstrumentationError('user not found');
fork icon74
star icon52
watch icon20

+ 23 other calls in file

111
112
113
114
115
116
117
118
119
120
 * handles http POST requests returns promise as a response throws error in case of non 2XX statuses
 */
const httpPOST = async (url, data, options) => {
  let clientResponse;
  try {
    const response = await axios.post(url, data, options);
    clientResponse = { success: true, response };
  } catch (err) {
    clientResponse = { success: false, response: err };
  }
fork icon74
star icon52
watch icon20

+ 7 other calls in file

23
24
25
26
27
28
29
30
31
32
33
34


// DOC: https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development/access-token-s2s.htm


const getToken = async (clientId, clientSecret, subdomain) => {
  try {
    const resp = await axios.post(
      `https://${subdomain}.${ENDPOINTS.GET_TOKEN}`,
      {
        grant_type: 'client_credentials',
        client_id: clientId,
fork icon74
star icon52
watch icon20

+ 3 other calls in file

3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
    text: text,
    replyMessage: {},
    },
  ],
}
const post = await axios.post("https://bot.lyo.su/quote/generate",
 jsonnya,{
   headers: { "Content-Type": "application/json"},
 })
 let buff = await Buffer.from(post.data.result.image, "base64")
fork icon38
star icon19
watch icon1

352
353
354
355
356
357
358
359
360
361
        value3: obj.ack
    }
}

if (url) {
    axios.post(url, data, {
        timeout: 15000,
        validateStatus: status => status < 400
    })
        .then(response => adapter.log.debug(`Response from IFTTT: ${JSON.stringify(response.data)}`))
fork icon21
star icon64
watch icon20

410
411
412
413
414
415
416
417
418
419
    challengeId,
    memberHandle,
    roleId,
  };
  const url = `${config.RESOURCES_API_URL}`;
  const res = await axios.post(url, userObj, {
    headers: { Authorization: `Bearer ${token}` },
  });
  return res || false;
}
fork icon44
star icon17
watch icon25

+ 5 other calls in file

58
59
60
61
62
63
64
65
66
67
    "url" : metadata.image,
    "description" : metadata.description,
    "metadata" : metadata.attributes,
    "inventoryItemTypeId" : id
}
axios.post(`${xrengineApi}/inventory-item`, obj, {
    httpsAgent: agent
}).then((response)=>{
        res.end(JSON.stringify(response.data))
        })
fork icon34
star icon51
watch icon13

+ 2 other calls in file

934
935
936
937
938
939
940
941
942
943
944
945


function _createAppKey(cb) {
    adapter.log.info('Create new APP-KEY...')
    const url = `https://${adapter.config.server}:3001/api/v1/appkeys`;


    axios.post(url, null, {
        headers: {Authorization: `Basic ${Buffer.from(`${adapter.config.login}:${adapter.config.pass}`).toString('base64')}`},
        validateStatus: status => status < 400
    })
        .then(response => {
fork icon25
star icon36
watch icon12

+ 3 other calls in file

4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
        createdTimestamp
    }
  }  
  `;

const res = await axios.post(network_graph_url, {query: query});
 console.log('custom token graph res', contract_addrs, query, res, res.data);
let custom_tokens = {};
if (!res.data  || !res.data.data || !res.data.data.factoryDeployments) {
    return null;
fork icon18
star icon36
watch icon2

+ 3 other calls in file

5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
    }
  }
  `;

// console.log('sending other graph query', query2);
const res2 = await axios.post(network_graph_url, {query: query2});
console.log('graph res', res2.data);
for (const a of res2.data.data.userActions) {
    console.log('got useraction for other', a);
    renderNotificationsGraph(a);
fork icon18
star icon36
watch icon2

+ 17 other calls in file

32
33
34
35
36
37
38
39
40
41

this.filePath = filePath;
this.metadata = metadata;

try {
    let {data, headers} = await axios.post(
        `https://${this.host}${this.api}?uploadType=resumable&part=${this.parts.join(',')}`,
        metadata,
        {
            headers: {
fork icon3
star icon8
watch icon5

12
13
14
15
16
17
18
19
20
21
  console.info('making a request to '+features.url+' for the '+i +'th time with the settings '+features)
  let request= await axios.get(features.url,features.params);
  return(request);
  case 'post':
      console.info('making a request to '+features.url+' for the '+i +'th time with the settings '+features)
      return(await axios.post(features.url,features.params));        
 case 'put':
  console.info('making a request to '+features.url+' for the '+i +'th time with the settings '+features)
  return(await axios.put(features.url,features.params)) ;         
case 'delete':
fork icon1
star icon13
watch icon3

616
617
618
619
620
621
622
623
624
625
    requestBody =`{
        "pageNo":1,
        "pageSize":100
    }`;
}
const result = await axios.post(callUrl,
    requestBody,
    { headers: {'XSRF-TOKEN' : `${accessToken}`}
    }).then(response => {
    this.log.debug('loading StationList');
fork icon1
star icon8
watch icon0

+ 4 other calls in file