I'm trying to send and SMS through serwersms and creation a Callout with JSON. This request works fine:
https://api2.serwersms.pl/messages/send_sms.json?username=LOGIN&password=PASS&phone=48500600700&text=TEXT&details=true
But my JSON doesn't. I'm getting {"error":{"code":1001,"type":"InvalidUser","message":"Nieprawid\u0142owy login lub has\u0142o"}}
. And it's 100% correct username and password.
My JSON:
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('username', 'LOGIN');
gen.writeStringField('password', 'PASS');
gen.writeFieldName('messages');
gen.writeStartArray();
for (integer i=0; i<2; i++){
gen.writeStartObject();
gen.writeStringField('phone', '48500600700');
gen.writeStringField('text', 'TEXT');
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeBooleanField('details', true);
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
String endpoint = 'https://api2.serwersms.pl/messages/send_sms.json'; //or maybe 'https://api2.serwersms.pl/' is right?
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setBody(jsonS);
Http http = new Http();
req.setTimeout(20000);
HTTPResponse response = http.send(req);
System.debug(response.getBody());
Documentation:
https://dev.serwersms.pl/en/https-api-v2/introduction and https://en.serwersms.pl/download/59 (14th page).
Help me please to fix it.
form-
data` instead. And then the response back will be JSON