ByBit API v5 returning error code 170130: "Data sent for parameter '%s' is not valid." No explanation of what parameter '%s' is - rest

I am trying to send a spot order using a unified account. There is absolutely no info about what this error message means and as far as I can tell from the ByBit v5 API docs I am doing everything correct. I have already established that the signature is formatted properly. This is the request being sent along:
RequestBuilder {
method: POST,
url: Url {
scheme: "https",
cannot_be_a_base: false,
username: "",
password: None,
host: Some(
Domain(
"api.bybit.com",
),
),
port: None,
path: "/v5/order/create",
query: None,
fragment: None,
},
headers: {
"content-type": "application/json",
"x-bapi-api-key": xxxxxxxxxxxxxx,
"x-bapi-timestamp": "1676755850417",
"x-bapi-sign": xxxxxxxxxxxxxxxx,
"x-bapi-recv-window": "5000",
},}
The request body that gets attached when the request is sent:
{"category":"spot","symbol":"ETHUSDT","side":"Sell","order_type":"Market","qty":"0.1"}
This is the Rust code used to send the request:
// Set up the HTTP client
let client = reqwest::Client::new();
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("X-BAPI-API-KEY", HeaderValue::from_str(&api_key)?);
headers.insert("X-BAPI-TIMESTAMP", HeaderValue::from_str(&timestamp)?);
headers.insert("X-BAPI-SIGN", HeaderValue::from_str(&sign)?);
headers.insert("X-BAPI-RECV-WINDOW", HeaderValue::from_static(recv_window));
let body = serde_json::to_string(&order)?;
// Submit the order
let request = client
.post("https://api.bybit.com/v5/order/create")
.headers(headers.clone())
.body(body.clone());
let response = request.send().await?;
And this is the response received:
Response {
url: Url {
scheme: "https",
cannot_be_a_base: false,
username: "",
password: None,
host: Some(
Domain(
"api.bybit.com",
),
),
port: None,
path: "/v5/order/create",
query: None,
fragment: None,
},
status: 200,
headers: {
"content-type": "application/json; charset=utf-8",
"content-length": "122",
"x-bapi-limit": "20",
"x-bapi-limit-status": "19",
"x-bapi-limit-reset-timestamp": "1676755851552",
"ret_code": "170130",
"traceid": "78d2bec29fead6e40447a63ba1eae5d9",
"timenow": "1676755851556",
"server": "Openresty",
"expires": "Sat, 18 Feb 2023 21:30:51 GMT",
"cache-control": "max-age=0, no-cache, no-store",
"pragma": "no-cache",
"date": "Sat, 18 Feb 2023 21:30:51 GMT",
"connection": "keep-alive",
},}

Had to ensure that it was "orderType" and not "order_type" in the signature string and request body.

Related

How to send sms to user using msg91 in flutter?

I have written the api call like this:
var response = await http.post(
Uri.parse("http://api.msg91.com/api/v2/sendsms"),
headers: {
"Content-Type": "application/json",
"authkey": "API key"
},
body: jsonEncode({
"sender": "note",
"route": "4",
"country": "91",
"flash": 1,
"sms":
{"message": "Message1", "to": "9999999999"}
}),
);
But this giving me error : {type: error, message: Invalid content type.Please send data in formdata,application/xml,application/json format, code: }
How can I correct this?
Try removing theses
"Content-Type": "application/json"
or replace it with
"Content-Type": "application/xml"
You should use multipart/form-data as content-type ->
"Content-Type": "multipart/form-data"

im fairly new and facing a problem about sending api request

I'm fairly new to the swift and I'm facing a problem with Alamofire what I'm trying to do is sending a get request with json body but I'm stuck heres my code:
struct request {
func getMessage(message:String){
let parameters: [String:Any] = [
"message" : [
"text": message,
"type":"text"
],
"type":"message",
"recipentId":"",
"info": [
"token":""
]
]
makeRequest(parameters: parameters)
}
func makeRequest(parameters:[String:Any]){
AF.request("https://bot.ortus4c.com/api/botController/token/5cc1f42e66d0ba0001dbf944",method: .post,parameters: parameters).response{
response in
debugPrint(response)
}
}
after executing this code i get:
[Request]: POST https://bot.ortus4c.com/api/botController/token/5cc1f42e66d0ba0001dbf944
[Request Body]:
info%5Btoken%5D=&message%5Btype%5D=text&message%5Btext%5D=Karakter&recipentId=&type=message
[Response]:
[Status Code]: 415
[Headers]:
Accept: application/json
Content-Length: 0
Date: Sat, 07 Mar 2020 19:10:23 GMT
Server: cloudflare
cf-cache-status: DYNAMIC
cf-ray: 57069dc3eaccad06-OTP
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
x-b3-traceid: b10ba988c0249901
[Response Body]:
None
[Data]: None
[Network Duration]: 0.3303520679473877s
[Serialization Duration]: 0.0s
[Result]: success(nil)
i dont get any result body compared to what expect when i send this request over postman:
"result": {
"messages": [
{
"type": "text",
"text": "Karakter Analizine Hoşgeldiniz. Analize başlamak için \"karakter\" yazınız"
},
{
"type": "text",
"text": "Test"
}
],
"tag": [
"start",
"finish"
],
"conversation_id": "5e63f302dc4bec0001883f01",
"intent_name": "Default Karakter",
"intent_id": "5ccb46ef66d0ba0001dbfcdf",
"intent_score": null,
"current_flow_id": "ee52db21-dae1-4587-80cd-7649798dddce1583608578222"
}
so how can i send this post request with this given body below:
let parameters: [String:Any] = [
"message" : [
"text": message,
"type":"text"
],
"type":"message",
"recipentId":"",
"info": [
"token":""
]
]
Now i have sent the request and got a body looking like this:
"result": {
"messages": [
{
"extra": {},
"question": "Adınız ?",
"type": "text",
"values": [
{
"text": ""
}
],
"askCount": 1,
"text": "Adınız ?",
"waitUserInput": true
}
],
"tag": [
"start",
"p_firstName",
1
],
"conversation_id": "5e63ffa0dc4bec0001883f10",
"intent_name": "Karakter Analizi",
"intent_id": "5cc20ae266d0ba0001dbf946",
"intent_score": "62.0",
"current_flow_id": "62ac3ac8-0cd7-43e5-b92b-f119d49c40d41583611808850"
}
how can i print the question variable to a label on my screen ?
Response code 415 means Unsupported Media Type and the Accept header of the response lets you know that the sever expects data to be sent as JSON. All you have to do is to let Alamofire know that it should encode parameters as JSON in the request body
AF.request("https://bot.ortus4c.com/api/botController/token/5cc1f42e66d0ba0001dbf944",
method: .post,
parameters: parameters,
encoding: JSONEncoding.default).response { response in
debugPrint(response)
}
you need to mention the encoding type as well while sending request. since your parameters data is json add encoding parameter as encoding: JSONEncoding.default
for example i have used as:
manager.request(url, method: httpMethod,
parameters: parameters,
encoding: JSONEncoding.default,
headers: configuredHeader)
.validate(statusCode: 200..<300)
.responseJSON(completionHandler: { [weak self] response in
self?.handleNetworkResponse(response: response, networkCompletionHandler: networkCompletionHandler)
})

Google Apps Script doesn't recognize "Host" header in HTTP POST request?

I'm trying to query ArcGIS Rest API from Google Apps script. Building the request in Postman works perfectly fine, but when I get the code into apps script, I'm having trouble that I cant seem to figure out. Here's the code:
function callEsri () {
var url = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0/query"
var params =
{
"async": true,
"crossDomain": true,
"url": "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0/query",
"method": "POST",
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "PostmanRuntime/7.20.1",
"Accept": "*/*",
"Cache-Control": "no-cache",
"Postman-Token": "[TOKEN]",
"Host": "services3.arcgis.com",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "125",
"Connection": "keep-alive",
"cache-control": "no-cache"
},
"data": {
"f": "json",
"where": "CITY_JUR LIKE '%Los Angeles%'",
"outSr": "4326",
"outFields": "TRL_NAME,ELEV_FT,CITY_JUR,PARK_NAME,FID"
}
}
var response = UrlFetchApp.fetch(url, params);
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
}
The Error I am getting is: Execution failed: Attribute provided with invalid value: Header:Host (line 28, file "Code")
Any reason why Google is not recognizing this and is there a way to fix this? Any help/advice is greatly appreciated.
As #TheMaster has already noted in the comments. You are already specifying the Host in the url.
Also you can take a look at the official documentation of URLFetchApp.
And in case you want more information in the head here you have the mozilla documentation on that header and also the RFC specifying the Host header.

Getting invalid_payment response from uber with 400 status code;using rest API

I am using REST API to book and uber ride using: https://api.uber.com/v1.2/requests .
It's not working with payment methods other than Cash.
I am getting 400 with code:invalid_payment
Can someone please help me out;
I am able to make payment using cash & Paytm for Indian locations.
I am not able to make payment using cash for US locations.
I am not able to make payment using the card for Indian & US locations.
When I add a new card via the Uber app and try to book a cab in the uber using the card it works; When I try to use the same card using my app it shows error. After this when I try to book a cab using the uber app; it doesn't work.
This the the response I am getting from Uber:
{
"data": {
"meta": {},
"errors": [
{
"status": 400,
"code": "invalid_payment",
"title": "The rider's payment method is invalid and they must update their billing info."
}
]
},
"status": 400,
"headers": {
"server": "nginx",
"strict-transport-security": "max-age=604800",
"x-frame-options": "SAMEORIGIN",
"content-type": "application/json",
"content-geo-system": "wgs-84",
"date": "Fri, 05 Apr 2019 06:28:50 GMT",
"x-content-type-options": "nosniff",
"content-length": "151",
"cache-control": "max-age=0",
"connection": "keep-alive",
"x-xss-protection": "1; mode=block"
},
"config": {
"transformRequest": {},
"transformResponse": {},
"timeout": 180000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"headers": {
"Accept": "application/json, text/plain, /*",
"Content-Type": "application/json",
"authorization": "Bearer JA.ZWU",
"Accept-Language": "en_US"
},
"method": "post",
"url": "https://api.uber.com/v1.2/requests",
"data": "{\"start_latitude\":40.8037381,\"start_longitude\":-73.9577813,\"end_latitude\":40.68780810000001,\"end_longitude\":-73.8057292,\"fare_id\":\"7636a3afa24d7648656aabbcc695bf094d4eed6d9323f3b10a5a5868a47c\",\"product_id\":\"b64-5de2-4539-a35a-986d6e58f186\",\"payment_method_id\":\"0xxxx-90ce-4c1d-a8c4-af7b1a00c3cf\"}"
},
"request": {
"UNSENT": 0,
"OPENED": 1,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"DONE": 4,
"readyState": 4,
"status": 400,
"timeout": 180000,
"withCredentials": true,
"upload": {},
"_aborted": false,
"_hasError": false,
"_method": "POST",
"_response": "{\"meta\":{},\"errors\":[{\"status\":400,\"code\":\"invalid_payment\",\"title\":\"The rider's payment method is invalid and they must update their billing info.\"}]}",
"_url": "https://api.uber.com/v1.2/requests",
"_timedOut": false,
"_trackingName": "unknown",
"_incrementalEvents": false,
"responseHeaders": {
"Server": "nginx",
"Strict-Transport-Security": "max-age=604800",
"X-Frame-Options": "SAMEORIGIN",
"Content-Type": "application/json",
"Content-Geo-System": "wgs-84",
"Date": "Fri, 05 Apr 2019 06:28:50 GMT",
"X-Content-Type-Options": "nosniff",
"Content-Length": "151",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"X-XSS-Protection": "1; mode=block"
},
"_requestId": null,
"_headers": {
"accept": "application/json, text/plain, /*",
"content-type": "application/json",
"authorization": "Bearer JA.VUNU",
"accept-language": "en_US"
},
"_responseType": "",
"_sent": true,
"_lowerCaseResponseHeaders": {
"server": "nginx",
"strict-transport-security": "max-age=604800",
"x-frame-options": "SAMEORIGIN",
"content-type": "application/json",
"content-geo-system": "wgs-84",
"date": "Fri, 05 Apr 2019 06:28:50 GMT",
"x-content-type-options": "nosniff",
"content-length": "151",
"cache-control": "max-age=0",
"connection": "keep-alive",
"x-xss-protection": "1; mode=block"
},
"_subscriptions": [],
"responseURL": "https://api.uber.com/v1.2/requests"
}
}
Actual result should be ride request accepted.

Bluemail - How to set user name and password

I call the service from app.js with below details but get response as
"description":"Not authorized"
Note that my username and password are correct but I may not be passing these correctly hence need help.
var options = {
host: 'bluemail.w3ibm.mybluemix.net',
port: 443,
path: '/rest/v2/emails',
method: 'POST',
headers: {
"Content-Type": "application/json; charset=utf8",
"username": "xxxxx",
"password": "xxxxxx"
}
};