Home

SPFX React JS POST REST Call not working - Cannot read property 'post' of undefined

%3CLINGO-SUB%20id%3D%22lingo-sub-1041352%22%20slang%3D%22en-US%22%3ESPFX%20React%20JS%20POST%20REST%20Call%20not%20working%20-%20Cannot%20read%20property%20'post'%20of%20undefined%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1041352%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20authenticate%20username%20and%20password%20only%20to%20a%20public%20Authorization.%3C%2FP%3E%3CP%3EIt%20is%20always%20throwing%20error%20-%20%22Cannot%20read%20property%20'post'%20of%20undefined%22.%3C%2FP%3E%3CP%3EI%20have%20used%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Ethis%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Econtext%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EhttpClient%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EPOST%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EpostURL%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EHttpClient%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Econfigurations%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Ev1%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EhttpClientOptions%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EBelow%20is%20the%20request%20body%20and%20headers%26nbsp%3B%3C%2FP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E(%3C%2FSPAN%3E%3CSPAN%3E'Cookie'%3C%2FSPAN%3E%3CSPAN%3E%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E'xxxxxx%3Dxxxxxxxxxxxxxxxxxxxxx'%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ErequestHeaders%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eappend%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E'Connection'%3C%2FSPAN%3E%3CSPAN%3E%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E'keep-alive'%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1041352%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPost%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPOST%20REST%20Call%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EReact%20JS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Server%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESPFx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Contributor

I am trying to authenticate username and password only to a public Authorization.

It is always throwing error - "Cannot read property 'post' of undefined".

I have used

this.context.httpClient.POST( postURL,  HttpClient.configurations.v1,   httpClientOptions)

Below is the request body and headers 

 

const body: string = JSON.stringify({
    'username': value1,
    'password': value2,
    'options': value3,
  });

  const requestHeaders: Headers = new Headers();
  requestHeaders.append('Content-type''application/json');
  requestHeaders.append('Accept''application/json');
  requestHeaders.append('Cache-Control''no-cache');

  requestHeaders.append('User-Agent''PostmanRuntime/7.20.1');
  requestHeaders.append('Postman-Token''xxxxxxxxxxxxxxxxxxxxxxxxxx');
  requestHeaders.append('Host''xxxxxx.oktapreview.com');
  requestHeaders.append('Accept-Encoding''gzip, deflate');
  requestHeaders.append('Content-Length''161');
  requestHeaders.append('Cookie''xxxxxx=xxxxxxxxxxxxxxxxxxxxx');
  requestHeaders.append('Connection''keep-alive');