title: Python REST call to VB
body: <p>First - I admit I'm in over my head on this.  I know how do do SOAP calls, but this REST stuff is all new to me.</p>
  <p>I have a Python script that calls our company CRM and it's working as it should.  I need to convert this over to VB6 (or even VB .net), but I can't seem to figure out just how to get the thing to work.  I know I'm talking to the CRM, but it keeps giving me an error (probably because I'm sending wrong data).</p>
  <p>Here's the working Python Script (NOTE: the authtoken variable comes from another script that's working fine):</p>
  <pre><code>fetchurl = https://URL-TO-THE-REST-FUNCTION
  
  searchheaders = {
      'accept': 'application/json; charset=utf-8',
      'Content-Type': 'application/json;charset=utf-8',
      'Authorization': 'Bearer ' + authtoken
      }
  
  payloadstring = {
      &quot;request&quot;: {
          &quot;companyNumber&quot;: 1,
          &quot;operatorInit&quot;: &quot;user&quot;,
          &quot;operatorPassword&quot;: &quot;Password&quot;,
          &quot;inputString&quot;: &quot;TEST_STRING&quot;
      }
  }
  
  payload = json.dumps(payloadstring)
  
  fetchresponse = requests.post(fetchurl,
      headers=searchheaders,
      data=payload,
      verify=False)
  
  apiResponse = fetchresponse.content
  
  print(json.loads(apiResponse))
  </code></pre>
  <p>And here's what I have so far in VB6</p>
  <pre><code>Dim sURL As String
  Dim strXML As String
  Dim xmlhttp As MSXML2.xmlhttp
  
  Set xmlhttp = New xmlhttp
  
  Open &quot;D:\API\token.dat&quot; For Input As #1
  Line Input #1, token$
  Close #1
  
  Data$ = &quot;'{&quot; &amp; Chr$(34) &amp; &quot;request&quot; &amp; Chr$(34) &amp; &quot;: {&quot;
  Data$ = Data$ &amp; Chr$(34) &amp; &quot;companyNumber&quot; &amp; Chr$(34) &amp; &quot;: 1,&quot;
  Data$ = Data$ &amp; Chr$(34) &amp; &quot;operatorInit&quot; &amp; Chr$(34) &amp; &quot;: &quot; &amp; Chr$(34) &amp; &quot;user&quot; &amp;     Chr$(34) &amp; &quot;,&quot;
  Data$ = Data$ &amp; Chr$(34) &amp; &quot;operatorPassword&quot; &amp; Chr$(34) &amp; &quot;: &quot; &amp; Chr$(34) &amp; &quot;password&quot; &amp; Chr$(34) &amp; &quot;,&quot;
  Data$ = Data$ &amp; Chr$(34) &amp; &quot;inputString&quot; &amp; Chr$(34) &amp; &quot;: &quot; &amp; Chr$(34) &amp; &quot;Work, Damnit!&quot; &amp; Chr$(34) &amp; &quot;}}'&quot;
  
  sURL = &quot;https://URL-TO-The-REST-FUNCTION&quot;
  strXML = Data$
  
  xmlhttp.open &quot;POST&quot;, sURL, True
  xmlhttp.setRequestHeader &quot;'accept':&quot;, &quot;'application/json; charset=utf-8'&quot;
  xmlhttp.setRequestHeader &quot;'Content-Type':&quot;, &quot;'application/json;charset=utf-8'&quot;
  xmlhttp.setRequestHeader &quot;'Authorization': 'Barer '&quot;, token$ &amp; &quot;'&quot;
  xmlhttp.send strXML
  </code></pre>
  <p>The Data$ looks like this:</p>
  <pre><code>'{&quot;request&quot;: {&quot;companyNumber&quot;: 1,&quot;operatorInit&quot;: &quot;user&quot;,&quot;operatorPassword&quot;: &quot;password&quot;,&quot;inputString&quot;: &quot;Work, Damnit!&quot;}}'
  </code></pre>
  <p>I know I'm at least talking to the server, the returned header looks like this:</p>
  <pre><code>Date: Fri, 04 Mar 2022 20:28:03 GMT
  Content-Type: application/json
  Content-Length: 24
  Connection: keep-alive
  x-frame-options: SAMEORIGIN
  x-transaction-id: 5dfcb31d-9d85-94ce-b6cd-81416aaab4c2
  strict-transport-security: max-age=31536000; includeSubDomains
  www-authenticate: Bearer realm=&quot;IONAPI&quot;
  server: ionapi-2022.02.00.995424
  x-envoy-decorator-operation: ionapi_gateway
  </code></pre>
  <p>And the response I'm getting is</p>
  <pre><code>{&quot;error&quot;:&quot;Unauthorized&quot;}
  </code></pre>
  <p>(I know the username/password I'm plugging in are good)</p>
  <p>Any help would be appreciated.
  Thanks</p>