1

I'd like to use ajax to retrieve a token.

In accordance to this documentation, below is the URL, request headers, and request body

POST https://api-production.august.com/session

Request Headers:

x-august-api-key: 727dba56-fe45–498d-b4aa-293f96aae0e5
x-kease-api-key: 727dba56-fe45–498d-b4aa-293f96aae0e5
Content-Type: application/json
Accept-Version: 0.0.1
User-Agent: August/Luna-3.2.2

Request Body: (JSON Encoded)
{
  "installId": <Random UUID>,
  "password": "XXXXXXXX",
  "identifier": "phone:+15555551234"
}

I've tried to implement this with ajax as such

  $.ajax({
            type: "POST",
            url: "https://api-production.august.com/session",
            dataType: "json",
            headers:{
                "x-august-api-key":"727dba56-fe45–498d-b4aa-293f96aae0e5",
                "x-kease-api-key":"727dba56-fe45–498d-b4aa-293f96aae0e5",
                "Content-Type": "application/json",
                "Accept-Version": "0.0.1",
                "User-Agent": "August/Luna-3.2.2"
            },
            data: JSON.stringify({installId: "7fb17963-21a8-4c23-8f81-121ed3298ad8",
            password: "password",
            identifier: "phone:+18885554444"})})

However I dont get the token and I get the following response:

abort: function abort()
always: function always()
catch: function catch()
done: function add()
fail: function add()
getAllResponseHeaders: function getAllResponseHeaders()
getResponseHeader: function getResponseHeader()
overrideMimeType: function overrideMimeType()
pipe: function pipe()
progress: function add()
promise: function promise()
readyState: 0
responseJSON: undefined
setRequestHeader: function setRequestHeader()
state: function state()
status: 0
statusCode: function statusCode()
statusText: "error"
then: function then()

The error is the following:

my error: ajax TypeError: Cannot convert string to ByteString because the character at index 13 has value 8211 which is greater than 255.

I've also tried running this in google chrome, but I get the following error:

"TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': Value is not a valid ByteString."

I've also tried the following to no avail as I get the same error:

   $.ajax({
                type: "POST",
                url: "https://api-production.august.com/session",
                dataType: "json",
                  beforeSend: function(request) {
                    request.setRequestHeader("x-august-api-key", "727dba56-fe45–498d-b4aa-293f96aae0e5");
                  },
                data: JSON.stringify({installId: "7fb17963-21a8-4c23-8f81-121ed3298ad8",
                password: "password",
                identifier: "phone:+18885554444"})})
sjakobi
  • 3,546
  • 1
  • 25
  • 43
Lynx
  • 23
  • 1
  • 6

1 Answers1

4

Your first error is kinda vague but it does mention "the character at index 13" (aka the 14th character). Your second error helps you see that the problem comes from setRequestHeader. So you should look at the strings that you pass to setRequestHeader and more specifically, the 14th character in those strings.

  1. x-august-api-key
  2. 727dba56-fe45498d-b4aa-293f96aae0e5

Now we ask ourselves, which one of these characters k or is more likely to be causing us issues? It should be intuitive that the is more likely to be the offending character so we take a closer look at it.

At this point we should be suspecting that we aren't using a hyphen character (ascii value of 45) but some other character that looks like a hyphen. Indeed, if we look up the ascii value 8211 (8211 comes from your first error) we see that the associated character is the en dash.

Some editors/viewers make the characters look different while others make it look the same. For me using Google Chrome to view this question, I can compare the hyphens in your key and I can see that the 2nd "hyphen" does not look like the rest. It's a tad longer.

hyphen:  -
en dash: –

So you should replace the en dash character with the hyphen character in your key. Then your string should be able to be converted to ByteString no problem.

Aust
  • 11,552
  • 13
  • 44
  • 74
  • The dash wasn't the issue with me, but the error pointing to a character at position _n_ was, so I looked and I had a char that looked like three periods `...` in my copy paste of the key, but was a single character. I removed that from the Bearer key I use, and the error is gone (from Swagger in this instance). +1 – Rin and Len Oct 22 '21 at 11:14
  • Further to my previous comment, it looks like this is an encoding bug in Firefox, I switched to new Edge(V.94) and did not have the same problem with the elipses character. Although removing the "wrong" char got rid of the ByteString error, I could not authenticate, now having a wrong token. – Rin and Len Oct 22 '21 at 11:45