esriRequest and the urban api?

1182
2
Jump to solution
07-11-2021 11:00 PM
RobStauder
Occasional Contributor

Hi,

I'm using the ArcGIS Urban API in a js app. I make requests to the urban api through esriRequest. Everything has been working well since April. However, last Thursday evening (July 😎 around 10:30 PM PST, the esriRequest code started throwing a status 400 message -

"Syntax Error: Cannot parse the unexpected character \"%\"."

Nothing changed with the code, it just started failing. It's basically doing this -

{urbanModels {title id owner}}

Here's an excerpt. (codepen)

I can copy the request from the profiler and run it successfully in the graqhql playground.

So did something change with esriRequest? It seems like the urban api has not been updated since February.

Or do I need to rewrite this using one of these libraries?

Thanks!

Rob

0 Kudos
1 Solution

Accepted Solutions
SandroMartis
Esri Contributor

Hi Rob

It seems that your request does not have the correct content-type and a proper JSON body.
I see "content-type: application/x-www-form-urlencoded" in the request headers from your codepen.

We did some changes to the Urban API infrastructure last week. It could be that the previous infrastructure somehow handled "application/x-www-form-urlencoded" requests and the new one does not anymore.

I updated your codepen to make it work again:
https://codepen.io/sandromartis/pen/PomWVMj

Notice the options for esriRequest:

 

const options = {
  method: "post",
  body: JSON.stringify({
    "query": "{urbanModels{title}}"
  })		
};

 


Let me know if that works for you.

Cheers,
Sandro

View solution in original post

0 Kudos
2 Replies
SandroMartis
Esri Contributor

Hi Rob

It seems that your request does not have the correct content-type and a proper JSON body.
I see "content-type: application/x-www-form-urlencoded" in the request headers from your codepen.

We did some changes to the Urban API infrastructure last week. It could be that the previous infrastructure somehow handled "application/x-www-form-urlencoded" requests and the new one does not anymore.

I updated your codepen to make it work again:
https://codepen.io/sandromartis/pen/PomWVMj

Notice the options for esriRequest:

 

const options = {
  method: "post",
  body: JSON.stringify({
    "query": "{urbanModels{title}}"
  })		
};

 


Let me know if that works for you.

Cheers,
Sandro

0 Kudos
RobStauder
Occasional Contributor

That worked! Thanks so much Sandro. I appreciate the help and guidance.

Best regards,

Rob

0 Kudos