简体   繁体   中英

No response from API

I have created an API call in excel to get data from a Wix database.

The call:

     Dim http As Object, JSON As Object
     Set http = CreateObject("MSXML2.XMLHTTP")
     http.Open "GET", "https://username.wixsite.com/mysite/_functions/Functionname", False
     http.setRequestHeader "Authorization", "myauthkey"
     http.Send
     MsgBox (http.responseText)

The javascript http backend file on Wix:

    import { ok, notFound, serverError } from 'wix-http-functions';
    import wixData from 'wixdata';

    export function get_Wixdata() {
    let options = {
    "headers": {
       "content-type": "application/json"
    }
    };
    return wixData.query("wix data collection name")
     .find()
     .then(results => {
        if (results.items.length > 0) {
            options.body ={
            "items": results.items
         }
         return ok(options);
       }
     })
    }

I tested the call (without authorisation) on JSON place holder and it worked fine.

Just trying to debug what's happening as I am getting "" as a response. Even if I enter the wrong API key I still get "", even a wrong url it's still a "" response.

I take it I am clearly way off the mark with what I am trying to do..

Did you tried put both headers in your request, like the following:

let headers = new Headers({ 
  'Content-Type': 'application/json', 
  'Authorization': '....' 
}); 

The issue was with the VBA call, the header was not needed.

Dim https As Object, JSON As Object
Set https = CreateObject("MSXML2.XMLHTTP")

With CreateObject("Microsoft.XMLHTTP")
    .Open "GET", "end point url", False
    .send
    response = .responseText
End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM