# Trouble with SparkIO.Webservices

**URL:** <https://community.particle.io/t/trouble-with-sparkio-webservices/25516>\
**Category:** Troubleshooting\
**Created:** [September 1, 2016, 6:05am UTC](https://community.particle.io/t/trouble-with-sparkio-webservices/25516 "2016-09-01T06:05:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![osprey](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/osprey/32/5600_2.png) [@osprey](https://community.particle.io/u/osprey)\
**Post date:** [September 1, 2016, 6:05am UTC](https://community.particle.io/t/trouble-with-sparkio-webservices/25516/1 "2016-09-01T06:05:15Z")

</div>

Hi,  
I have a .net application that has been running for months without issue. It uses SparkIO.Webservices so that it connects to my account and retrieves information published by my devices.

Today it just stopped working and closes without even giving a proper error message. Looking at the code, I found out that it is stopping on this line:

```
core = New EventsAPI([username], [password], "")

```

Looking at the parameters that are supposed to be sent to this function I noticed that the fifth argument, when not supplied, defaults to “[https://api.spark.io](https://api.spark.io)”. I tried changing the argument to “[https://api.particle.io](https://api.particle.io)”. The effect was that now the application is not closing on it’s own, but the server is returning this error:

```
The remote server returned an error: (401) Unauthorized.

```

I am sure there is nothing wrong with my credentials since they have not been changed and I can still access the console with them.

Is anyone else encountering this problem?

Thank you.

**UPDATE #1:**

The error I am getting after changing the “urlSparkCloud” argument occurs on this line of code:

```
core.StartPublicEventsByName("{variablename}", True)

```

**UPDATE #2:**

Found a temporary solution by changing:

```
core = New EventsAPI([username], [password], "")

```

with

```
core = New EventsAPI([AccessToken])

```

and

```
core.StartPublicEventsByName("{variablename}", True) 

```

with

```
core.StartOwnedDeviceEventsByName("{variablename}", True)

```

I got the Access token from the Particle Console but I don’t how long till it expires.

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [September 2, 2016, 10:47am UTC](https://community.particle.io/t/trouble-with-sparkio-webservices/25516/2 "2016-09-02T10:47:58Z")

</div>

Which library are you using?

There is a param that allows the creation of a non-expiring access token.

---

<div class="post-metadata">

**Author:** ![osprey](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/osprey/32/5600_2.png) [@osprey](https://community.particle.io/u/osprey)\
**Post date:** [September 2, 2016, 12:36pm UTC](https://community.particle.io/t/trouble-with-sparkio-webservices/25516/3 "2016-09-02T12:36:03Z")

</div>

This is what I am using:

> **[SparkIO.WebServices 1.3.0](https://www.nuget.org/packages/SparkIO.WebServices/)**
>
> .Net library for interacting with the Spark Core and Electron. Provides support for calling functions and variables. Also allows receipt of published events from a Core.

I believe I found a solution for the access token but I have only been testing it for a day:

```
MyCore = New CoreAPI("[email]", "[password]", , , "https://api.particle.io")
Dim MyAccessToken As CreateTokenInfo = MyCore.CreateToken("[email]", "[password]")
Dim strAccessToken = MyAccessToken.AccessToken.ToString()
core = New EventsAPI(strAccessToken)
```
