skip to Main Content

I have tried in posting API data Its working fine getting proper response ,but i try to do in JavaScript with fetch method through not getting , getting error Status Code: 500 message Invalid client credentials provided.Please check your required your text header parameters.i was sent proper data as sending in postman


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Totam itaque numquam temporibus neque nemo consectetur debitis! Nisi, enim deleniti. Nostrum, beatae. Consequuntur, cum eaque harum at sunt deserunt recusandae eos.</h1>

    <script>
        const response =  fetch('https://einvoice.pos.bharuwa.com:6015/api/generateeinvoice', {
               method: "POST", 
               mode: "cors",
               header:
                      {
                        "Content-Type": "application/json",
                        "Content-Length":344,
                        "x-api-key": "C4789E11-555B-4CC7-9A69-BC1F35B8659E",
                        "x-clientId": "C4789E11-555B-4CC7-9A69-BC1F35B8659E",
                        "x-api-secret": "44461e58-7ab3-4cf7-b06e-9b68893e4902"
                      },
                      
    
  
                            body: {
                          "Version": "1.1",
                          "TranDtls": {
                            "TaxSch": "GST",
                            "SupTyp": "B2B",
                            "RegRev": "Y",
                            "EcmGstin": null,
                            "IgstOnIntra": "N"
                          },
                          "DocDtls": {
                            "Typ": "INV",
                            "No": "DOC/029",
                            "Dt": "09/08/2021"
                          },
                          "SellerDtls": {
                            "Gstin": "01AMBPG7773M002",
                                "LglNm": "ABC Travels Pvt Ltd",
                                "TrdNm": null,
                                "Addr1": "5th block, kuvempu layout",
                                "Addr2": null,
                                "Loc": "Jammu and Kashmir",
                                "Pin": 181102, 
                            "Stcd": "01",
                            "Ph": "9000000000",
                            "Em": "[email protected]"
                          },
                          "BuyerDtls": {
                            "Gstin": "29AWGPV7107B1Z1",
                            "LglNm": "XYZ company pvt ltd",
                            "TrdNm": "XYZ Industries",
                            "Pos": "12",
                            "Addr1": "7th block, kuvempu layout",
                            "Addr2": "kuvempu layout",
                            "Loc": "GANDHINAGAR",
                            "Pin": 562160,
                            "Stcd": "29",
                            "Ph": "91111111111",
                            "Em": "[email protected]"
                          },
                          "DispDtls": {
                            "Nm": "ABC company pvt ltd",
                            "Addr1": "7th block, kuvempu layout",
                            "Addr2": "kuvempu layout",
                            "Loc": "Banagalore",
                            "Pin": 562160,
                            "Stcd": "29"
                          },
                          "ShipDtls": {
                            "Gstin": "29AWGPV7107B1Z1",
                            "LglNm": "CBE company pvt ltd",
                            "TrdNm": "kuvempu layout",
                            "Addr1": "7th block, kuvempu layout",
                            "Addr2": "kuvempu layout",
                            "Loc": "Banagalore",
                            "Pin": 562160,
                            "Stcd": "29"
                          },
                          "ItemList": [
                            {
                              "SlNo": "1",
                              "PrdDesc": "Rice",
                              "IsServc": "N",
                              "HsnCd": "1001",
                              "Barcde": "123456",
                              "Qty": 100.345,
                              "FreeQty": 10,
                              "Unit": "BAG",
                              "UnitPrice": 99.545,
                              "TotAmt": 9988.84,
                              "Discount": 10,
                              "PreTaxVal": 1,
                              "AssAmt": 9978.84,
                              "GstRt": 12.0,
                              "IgstAmt": 1197.46,
                              "CgstAmt": 0,
                              "SgstAmt": 0,
                              "CesRt": 5,
                              "CesAmt": 498.94,
                              "CesNonAdvlAmt": 10,
                              "StateCesRt": 12,
                              "StateCesAmt": 1197.46,
                              "StateCesNonAdvlAmt": 5,
                              "OthChrg": 10,
                              "TotItemVal": 12897.7,
                              "OrdLineRef": "3256",
                              "OrgCntry": "AG",
                              "PrdSlNo": "12345",
                              "BchDtls": {
                                "Nm": "123456",
                                "ExpDt": "01/08/2021",
                                "WrDt": "01/09/2021"
                              },
                              "AttribDtls": [
                                {
                                  "Nm": "Rice",
                                  "Val": "10000"
                                }
                              ]
                            }
                          ],
                          "ValDtls": {
                            "AssVal": 9978.84,
                            "CgstVal": 0,
                            "SgstVal": 0,
                            "IgstVal": 1197.46,
                            "CesVal": 508.94,
                            "StCesVal": 1202.46,
                            "Discount": 10,
                            "OthChrg": 20,
                            "RndOffAmt": 0.3,
                            "TotInvVal": 12908,
                            "TotInvValFc": 12897.7
                          },
                          "PayDtls": {
                            "Nm": "ABCDE",
                            "AccDet": "5697389713210",
                            "Mode": "Cash",
                            "FinInsBr": "SBIN11000",
                            "PayTerm": "100",
                            "PayInstr": "Gift",
                            "CrTrn": "test",
                            "DirDr": "test",
                            "CrDay": 100,
                            "PaidAmt": 10000,
                            "PaymtDue": 5000
                          },
                          "RefDtls": {
                            "InvRm": "TEST",
                            "DocPerdDtls": {
                              "InvStDt": "01/08/2021",
                              "InvEndDt": "01/09/2021"
                            },
                            "PrecDocDtls": [
                              {
                                "InvNo": "DOC/004",
                                "InvDt": "01/08/2021",
                                "OthRefNo": "123456"
                              }
                            ],
                            "ContrDtls": [
                              {
                                "RecAdvRefr": "Doc/005",
                                "RecAdvDt": "01/08/2021",
                                "TendRefr": "Abc001",
                                "ContrRefr": "Co123",
                                "ExtRefr": "Yo456",
                                "ProjRefr": "Doc-457",
                                "PORefr": "Doc-790",
                                "PORefDt": "01/08/2021"
                              }
                            ]
                          },
                          "AddlDocDtls": [
                            {
                              "Url": "https://einv-apisandbox.nic.in",
                              "Docs": "Test Doc",
                              "Info": "Document Test"
                            }
                          ],
                          "ExpDtls": {
                            "ShipBNo": "A-248",
                            "ShipBDt": "01/08/2021",
                            "Port": "INABG1",
                            "RefClm": "N",
                            "ForCur": "AED",
                            "CntCode": "AE",
                            "ExpDuty": null
                          },
                          "EwbDtls": {
                            "TransId": "12AWGPV7107B1Z1",
                            "TransName": "XYZ EXPORTS",
                            "Distance": 100,
                            "TransDocNo": "DOC03",
                            "VehNo": "ka123456",
                            "VehType": "R",
                            "TransMode": "1"
                          }
                        }, // body data type must match "Content-Type" header
                          });

    </script>
</body>
</html>[[enter image description here](https://i.stack.imgur.com/A9agz.png)](https://i.stack.imgur.com/7QaRU.png)

2

Answers


  1. Before anything if that’s real API creds I recommend removing it from post.

    A few things I noticed and referencing Fetch api doc for more details.

    • your header: { property should be plural, headers: {
    • wrap your JSON data with JSON.stringify({...}) in the body: JSON.stringify(yourJSONData)
    • recommend using async/await, see Fetch api doc for an example

    Working Example, just insert your creds.

    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <h1>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Totam itaque numquam temporibus neque nemo consectetur debitis! Nisi, enim deleniti. Nostrum, beatae. Consequuntur, cum eaque harum at sunt deserunt recusandae eos.</h1>
    
        <script>
         async function postData() {
            const response = await fetch('https://einvoice.pos.bharuwa.com:6015/api/generateeinvoice', {
                   method: "POST", 
                   mode: "cors",
                   headers:
                          {
                            "Content-Type": "application/json",
                            "Content-Length":344,
                            "x-api-key": "put-your-key",
                            "x-clientId": "put-your-key",
                            "x-api-secret": "put-your-key"
                          },
                  body: JSON.stringify(
    {
      "Version": "1.1",
      "TranDtls": {
        "TaxSch": "GST",
        "SupTyp": "B2B",
        "RegRev": "Y",
        "EcmGstin": null,
        "IgstOnIntra": "N"
      },
      "DocDtls": {
        "Typ": "INV",
        "No": "DOC/029",
        "Dt": "09/08/2021"
      },
      "SellerDtls": {
        "Gstin": "01AMBPG7773M002",
        "LglNm": "ABC Travels Pvt Ltd",
        "TrdNm": null,
        "Addr1": "5th block, kuvempu layout",
        "Addr2": null,
        "Loc": "Jammu and Kashmir",
        "Pin": 181102,
        "Stcd": "01",
        "Ph": "9000000000",
        "Em": "[email protected]"
      },
      "BuyerDtls": {
        "Gstin": "29AWGPV7107B1Z1",
        "LglNm": "XYZ company pvt ltd",
        "TrdNm": "XYZ Industries",
        "Pos": "12",
        "Addr1": "7th block, kuvempu layout",
        "Addr2": "kuvempu layout",
        "Loc": "GANDHINAGAR",
        "Pin": 562160,
        "Stcd": "29",
        "Ph": "91111111111",
        "Em": "[email protected]"
      },
      "DispDtls": {
        "Nm": "ABC company pvt ltd",
        "Addr1": "7th block, kuvempu layout",
        "Addr2": "kuvempu layout",
        "Loc": "Banagalore",
        "Pin": 562160,
        "Stcd": "29"
      },
      "ShipDtls": {
        "Gstin": "29AWGPV7107B1Z1",
        "LglNm": "CBE company pvt ltd",
        "TrdNm": "kuvempu layout",
        "Addr1": "7th block, kuvempu layout",
        "Addr2": "kuvempu layout",
        "Loc": "Banagalore",
        "Pin": 562160,
        "Stcd": "29"
      },
      "ItemList": [
        {
          "SlNo": "1",
          "PrdDesc": "Rice",
          "IsServc": "N",
          "HsnCd": "1001",
          "Barcde": "123456",
          "Qty": 100.345,
          "FreeQty": 10,
          "Unit": "BAG",
          "UnitPrice": 99.545,
          "TotAmt": 9988.84,
          "Discount": 10,
          "PreTaxVal": 1,
          "AssAmt": 9978.84,
          "GstRt": 12,
          "IgstAmt": 1197.46,
          "CgstAmt": 0,
          "SgstAmt": 0,
          "CesRt": 5,
          "CesAmt": 498.94,
          "CesNonAdvlAmt": 10,
          "StateCesRt": 12,
          "StateCesAmt": 1197.46,
          "StateCesNonAdvlAmt": 5,
          "OthChrg": 10,
          "TotItemVal": 12897.7,
          "OrdLineRef": "3256",
          "OrgCntry": "AG",
          "PrdSlNo": "12345",
          "BchDtls": {
            "Nm": "123456",
            "ExpDt": "01/08/2021",
            "WrDt": "01/09/2021"
          },
          "AttribDtls": [
            {
              "Nm": "Rice",
              "Val": "10000"
            }
          ]
        }
      ],
      "ValDtls": {
        "AssVal": 9978.84,
        "CgstVal": 0,
        "SgstVal": 0,
        "IgstVal": 1197.46,
        "CesVal": 508.94,
        "StCesVal": 1202.46,
        "Discount": 10,
        "OthChrg": 20,
        "RndOffAmt": 0.3,
        "TotInvVal": 12908,
        "TotInvValFc": 12897.7
      },
      "PayDtls": {
        "Nm": "ABCDE",
        "AccDet": "5697389713210",
        "Mode": "Cash",
        "FinInsBr": "SBIN11000",
        "PayTerm": "100",
        "PayInstr": "Gift",
        "CrTrn": "test",
        "DirDr": "test",
        "CrDay": 100,
        "PaidAmt": 10000,
        "PaymtDue": 5000
      },
      "RefDtls": {
        "InvRm": "TEST",
        "DocPerdDtls": {
          "InvStDt": "01/08/2021",
          "InvEndDt": "01/09/2021"
        },
        "PrecDocDtls": [
          {
            "InvNo": "DOC/004",
            "InvDt": "01/08/2021",
            "OthRefNo": "123456"
          }
        ],
        "ContrDtls": [
          {
            "RecAdvRefr": "Doc/005",
            "RecAdvDt": "01/08/2021",
            "TendRefr": "Abc001",
            "ContrRefr": "Co123",
            "ExtRefr": "Yo456",
            "ProjRefr": "Doc-457",
            "PORefr": "Doc-790",
            "PORefDt": "01/08/2021"
          }
        ]
      },
      "AddlDocDtls": [
        {
          "Url": "https://einv-apisandbox.nic.in",
          "Docs": "Test Doc",
          "Info": "Document Test"
        }
      ],
      "ExpDtls": {
        "ShipBNo": "A-248",
        "ShipBDt": "01/08/2021",
        "Port": "INABG1",
        "RefClm": "N",
        "ForCur": "AED",
        "CntCode": "AE",
        "ExpDuty": null
      },
      "EwbDtls": {
        "TransId": "12AWGPV7107B1Z1",
        "TransName": "XYZ EXPORTS",
        "Distance": 100,
        "TransDocNo": "DOC03",
        "VehNo": "ka123456",
        "VehType": "R",
        "TransMode": "1"
      }
    }
                  ) // body data type must match "Content-Type" header
            });
            return response.json();
         }
          
          
      postData().then((data) => {
        console.log(data); // JSON data parsed by `data.json()` call
      });
          
        </script>
    </body>
    </html>
    Login or Signup to reply.
  2. The error message "Status Code: 500 message Invalid client credentials provided" indicates that there is an issue with the credentials provided in the request headers.

    In your JavaScript code, there seems to be a mistake in the header key name. It should be headers instead. Additionally, the Content-Length header should not be manually set, as it is calculated automatically. You can remove that header.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search