# An error has occurred

**URL:** <https://forums.eveonline.com/t/an-error-has-occurred/241426>\
**Category:** Third Party Developers\
**Created:** [May 15, 2020, 10:16pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426 "2020-05-15T22:16:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 15, 2020, 10:16pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/1 "2020-05-15T22:16:03Z")

</div>

Hello there,

I have started using (trying to) the new API, and I am a bit confused as I am getting an error which is not an error. I am running the following code in my machine:

```
$bodyData = array(
     "grant_type" => "authorization_code",
     "code" => $code);

 $headerData = array(
    "Authorization:Basic " . base64_encode(clientID.":".secretKey),
    "Content-Type:application/json",
    'Host:login.eveonline.com'
 );

 $curl = curl_init();

 $url = 'https://login.eveonline.com/v2/oauth/token/';

 $certificate = "C:\wamp64\certs\cacert.pem";
 curl_setopt($curl, CURLOPT_CAINFO, $certificate);
 curl_setopt($curl, CURLOPT_CAPATH, $certificate);

 curl_setopt($curl, CURLOPT_URL, $url);
 curl_setopt($curl, CURLOPT_POST, true);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodyData));
 curl_setopt($curl, CURLOPT_HTTPHEADER, $headerData);

 $response = curl_exec($curl);
 if( $response === false){
     echo 'Curl error: ' . curl_error($curl);
 }
 else{
     echo $response;
 }

```

This was supposed to complete the step two in the authorization but, although the curl command is not generating any error, the response I am getting is:

`{ "Message" : "An error has occurred." }`

I am not sure what I am doing wrong and unfortunately Google has not been of great help until now.

I tried to run the same from the command line as

`curl -XPOST -H "Content-Type:application/json" -H "Authorization:Basic ZWRlODdiOWIzZGMyNGR...SE1mREpYTFlDNWVjRkptSGQwMFlzWUc4MXpETU9vcDZIYmZYeg==" -d '{"grant_type":"authorization_code", "code":"DKVHTD6MQXt-t9YNe4SVD8ATe...mwl0NBVo35uImZG9IxbHhhjda"}' https://login.eveonline.com/v2/oauth/token`

and got exactly the same response.

Any hint would be appreciated.

Thanks a lot!

GK

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [May 15, 2020, 10:30pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/2 "2020-05-15T22:30:15Z")

</div>

See the docs on how to make these requests: [https://docs.esi.evetech.net/docs/sso/web\_based\_sso\_flow.html](https://docs.esi.evetech.net/docs/sso/web_based_sso_flow.html).

My first guess is you’re using `JSON`, when it should be `application/x-www-form-urlencoded`.

---

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 15, 2020, 10:42pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/3 "2020-05-15T22:42:44Z")

</div>

That solved the issue; I was looking at old documentation. That has brought another problem

`{"error":"invalid_grant","error_description":"Grant type is not supported."}`

but I hope to get it done reading the correct docs.

Thanks a lot!

GK

---

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 18, 2020, 9:53am UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/4 "2020-05-18T09:53:24Z")

</div>

@Blacksmoke16, sorry to bother you. I was not able to find any solution re the second error. Not really sure which grant is the one giving the error.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [May 18, 2020, 12:43pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/5 "2020-05-18T12:43:11Z")

</div>

Can you share your latest code/request?

---

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 18, 2020, 12:57pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/6 "2020-05-18T12:57:01Z")

</div>

This?

[https://login.eveonline.com/oauth/authorize?response\_type=code&redirect\_uri=http%3A%2F%2Flocalhost%2Foauth-callback%2Findex.php&client\_id=ede87b9b3dc24dae91c9d991ed481dc6&scope=esi-markets.structure\_markets.v1%20esi-assets.read\_corporation\_assets.v1&state=QZZmcf1Nr6](https://login.eveonline.com/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-callback%2Findex.php&client_id=ede87b9b3dc24dae91c9d991ed481dc6&scope=esi-markets.structure_markets.v1%20esi-assets.read_corporation_assets.v1&state=QZZmcf1Nr6)

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [May 18, 2020, 1:03pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/7 "2020-05-18T13:03:46Z")

</div>

Well, not quite, but I think that actually shows the problem. Carefully read thru [https://docs.esi.evetech.net/docs/sso/web\_based\_sso\_flow.html](https://docs.esi.evetech.net/docs/sso/web_based_sso_flow.html) and make sure you’re following the steps. Notice that the URLs are different than what you’re using. I.e. you want to use `/v2/oauth/authorize/` and `/v2/oauth/token`.

---

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 18, 2020, 1:31pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/8 "2020-05-18T13:31:50Z")

</div>

That v2 slipped through the cracks in the first call. Thanks for that.

However, `/v2/oauth/token` is the one to transform the code I get into a token.

As I understood it, first I have to call `/v2/oauth/authorize` and when I get the code, then I use this code to pass it to `/v2/oauth/token` together with the secret key, client ID, etc, … as in the code I shared in the first post.

That is what I understood from the page you sent me, which I have almost memorized 😃

First I call `https://login.eveonline.com/v2/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-callback%2Findex.php&client_id=ede87b9b3dc24...9d991ed481dc6&scope=esi-markets.structure_markets.v1%20esi-assets.read_corporation_assets.v1&state=FhBvVotmtFJjUrsgpmi3nMCGHoJkTnhH`

and get

`http://localhost/oauth-callback/index.php?code=8VmoXRWTWkC3LLjL38qnaA&state=FhBvVotmtFJjUrsgpmi3nMCGHoJkTnhH`

and I use the code to call `/v2/oauth/token`, right?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [May 18, 2020, 2:27pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/9 "2020-05-18T14:27:13Z")

</div>

Yes, you use that `code` to get a token. Starting on step 4 on that guide ^.

---

<div class="post-metadata">

**Author:** ![Rtg\_Quack](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rtg_quack/32/259589_2.png) [@Rtg\_Quack](https://forums.eveonline.com/u/Rtg_Quack)\
**Post date:** [May 18, 2020, 5:31pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/10 "2020-05-18T17:31:16Z")

</div>

Hey @Gimhae_Kim, are you aware of [https://esi.evetech.net/ui/](https://esi.evetech.net/ui/) and the capabilities of the API as well how to use it?

---

<div class="post-metadata">

**Author:** ![Gimhae\_Kim](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/gimhae_kim/32/205843_2.png) [@Gimhae\_Kim](https://forums.eveonline.com/u/Gimhae_Kim)\
**Post date:** [May 18, 2020, 9:46pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/11 "2020-05-18T21:46:25Z")

</div>

@Rtg_Quack I was indeed. Thanks.

It was me forgetting how to do PHP no more.

Thank you both!

GK

---

<div class="post-metadata">

**Author:** ![Rtg\_Quack](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/rtg_quack/32/259589_2.png) [@Rtg\_Quack](https://forums.eveonline.com/u/Rtg_Quack)\
**Post date:** [May 20, 2020, 8:53pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/12 "2020-05-20T20:53:53Z")

</div>

If you use PHP to connect to ESI I might suggest to use a robust OAUTH2 implementation like Evelabs\OAuth2  
I use it in my own project, see in particular method eveSsoLogin() in [https://github.com/chrRtg/eve-skylizer/blob/master/module/User/src/Service/EveSSOManager.php](https://github.com/chrRtg/eve-skylizer/blob/master/module/User/src/Service/EveSSOManager.php)

Hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![Hamish\_Grayson](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/hamish_grayson/32/303983_2.png) [@Hamish\_Grayson](https://forums.eveonline.com/u/Hamish_Grayson)\
**Post date:** [July 5, 2020, 11:05pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/13 "2020-07-05T23:05:15Z")

</div>

There seem to 5 or six folks on the planet who can make ESI work. So it’s a good thing they broke my spreadsheets to those 5 dudes can do the exact same thing they were dong with CREST, which was mostly usable by the average person.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/eveonline/original/3X/4/1/41ec4921cbaca7a6f9ea556e7cc20018461eae5e.png) [@system](https://forums.eveonline.com/u/system)\
**Post date:** [October 3, 2020, 11:05pm UTC](https://forums.eveonline.com/t/an-error-has-occurred/241426/14 "2020-10-03T23:05:37Z")

</div>

Closed on October 3, 2020, 11:05pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
