Docusign Api Call Issue in React js

85 Views Asked by At

After getting Access Token, I made API call on Postman (https://demo.docusign.net/restapi/v2.1/accounts/{account_id} which was successfull. But when i tried to make simple axios/fetch request on React js by making a function. It is constantly showing me error:

AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …} code : "ERR_NETWORK" config : {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …} message : "Network Error" name : "AxiosError" request : XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} stack : "AxiosError: Network Error\n at XMLHttpRequest.handleError (http://localhost:3000/static/js/bundle.js:41459:14)" [[Prototype]] : Error .

Can anyone tell that what is the issue in it?

I tried the code:

import React, { useEffect } from 'react'; import axios from 'axios';

const User = () => { useEffect(() => { const apiUrl = 'https://demo.docusign.net/restapi/v2.1/accounts/{myaccount id here}'; const token = //mytoken; const config = { headers: { 'Authorization': Bearer ${token}, }, };

axios.get(apiUrl, config)
  .then(response => {
    // Handle the response data here
    console.log(response.data);
  })
  .catch(error => {
    // Handle the error here
    console.error(error);
  });

}, []);

return Check the browser console for the API response.; };

export default User;

1

There are 1 best solutions below

0
Larry K On

Are you trying to directly call the DocuSign API from a React application running in a browser?

If so, then the browser (not DocuSign and not React) will require you to use CORS. DocuSign supports CORS, start with the blog post. And see the MDN CORS docs too.

Also, I suggest that you look into using the web standard fetch to make your API calls rather than the axios library.