2017-07-06 71 views
0

我正在嘗試使用V3 API創建事件。我送的參數是:無法使用API​​創建Eventbrite事件

var _event = { 
    "event" : { 
     "name": { 
      "html": "Test Event 01" 
     }, 
     "description": { 
      "html": "Test Event 01" 
     }, 
     "start": { 
      "timezone": "America/Chicago", 
      "utc": "2017-07-10T18:00:00Z" 
     }, 
     "end": { 
      "timezone": "America/Chicago", 
      "utc": "2017-07-10T20:00:00Z" 
     }, 
     "currency": "USD" 
    } 
}; 

這就是我要打發使用的的NodeJS要求:

var request = require('request'); 
var _headers = { 
    'Authorization': 'Bearer ' + _token, 
    'Content-Type': 'application/json', 
} 

// Configure the request 
var options = { 
    url: EVENTBRITE_API_URL + "events/", 
    method: 'POST', 
    headers: _headers, 
    form: _event 
} 

我自己也嘗試Content-Type: application/x-url-form-encoded和內部optionsJSON.stringify(_event)。我也試圖改變_event對象:

var _event = {   
    "name": { 
     "html": "Test Event 01" 
    }, 
    "description": { 
     "html": "Test Event 01" 
    }, 
    "start": { 
     "timezone": "America/Chicago", 
     "utc": "2017-07-10T18:00:00Z" 
    }, 
    "end": { 
     "timezone": "America/Chicago", 
     "utc": "2017-07-10T20:00:00Z" 
    }, 
    "currency": "USD" 
}; 

我已經嘗試了所有的組合,但我總是得到相同的迴應:

{ 
    "status_code": 400, 
    "error_description": "There are errors with your arguments: event[currency] - Unknown parameter, event.start.timezone - This field is required., event.currency - This field is required., event.start.utc - This field is required., event[start][timezone] - Unknown parameter, event.end.utc - This field is required., event[end][utc] - Unknown parameter, event[description][html] - Unknown parameter, event[name][html] - Unknown parameter, event[end][timezone] - Unknown parameter, event[start][utc] - Unknown parameter, event.end.timezone - This field is required., event.name.html - This field is required.", 
    "error": "ARGUMENTS_ERROR" 
} 

有什麼樣創建活動要求的任何地方我可以看看?以上要求有什麼問題?

回答

0

我認爲問題在於您目前正在發送表格帖子(憑藉使用form選項),但是您的參數應該看起來像{ "event.currency": "USD", "event.name.html": "Test Event 01", ... }。如果你想發送JSON,你需要使用json: true,並通過一個JSON序列化的身體:如果你想堅持使用表單POST

var request = require('request'); 
var _headers = { 
    'Authorization': 'Bearer ' + _token, 
    'Content-Type': 'application/json', 
} 

// Configure the request 
var options = { 
    url: EVENTBRITE_API_URL + "events/", 
    method: 'POST', 
    headers: _headers, 

    // Instead of this: 
    // form: _event 

    // use this: 
    json: true, // says you're sending JSON 
    body: _event, // so the body should be JSON-serializable 
}; 

,我想這應該這樣做:

var _event = { 
    "event.name.html": "Test Event 01", 
    "event.description.html": "Test Event 01", 
    "event.start.timezone": "America/Chicago", 
    "event.start.utc": "2017-07-10T18:00:00Z", 
    "event.end.timezone": "America/Chicago", 
    "event.end.utc": "2017-07-10T20:00:00Z", 
    "event.currency": "USD", 
}; 

var request = require('request'); 
var _headers = { 
    'Authorization': 'Bearer ' + _token, 
    'Content-Type': 'application/x-www-form-urlencoded', 
} 

// Configure the request 
var options = { 
    url: EVENTBRITE_API_URL + "events/", 
    method: 'POST', 
    headers: _headers, 
    form: _event, 
}; 
+0

順便說一句,這種事情的一個有用的調試工具是https://requestb.in/。將您的API請求發送到那裏,而不是發送到Eventbrite API,並且您可以準確查看您要發送的內容。在那裏,我相信你會看到你發送一個表單編碼的身體而不是JSON。 – smarx

+0

輝煌。絕對的輝煌。你救了我的一天! – User2682

相關問題