# Create Lead on API - State field produces error.

**URL:** <https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139>\
**Category:** Development\
**Created:** [August 4, 2015, 3:20pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139 "2015-08-04T15:20:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![wessel](https://avatars.discourse-cdn.com/v4/letter/w/53a042/32.png) [@wessel](https://forum.mautic.org/u/wessel)\
**Post date:** [August 4, 2015, 3:20pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/1 "2015-08-04T15:20:50Z")

</div>

Creating a Lead through the API, we get an error when we try to set the ‘State’ field. We tried values both of ‘CA’ and ‘California’ but both trigger a ‘401 Bad Request’.  
  
  
  
How can we set the State correctly when using the API?

---

<div class="post-metadata">

**Author:** ![wessel](https://avatars.discourse-cdn.com/v4/letter/w/53a042/32.png) [@wessel](https://forum.mautic.org/u/wessel)\
**Post date:** [August 4, 2015, 3:20pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/2 "2015-08-04T15:20:50Z")

</div>

Creating a Lead through the API, we get an error when we try to set the ‘State’ field. We tried values both of ‘CA’ and ‘California’ but both trigger a ‘401 Bad Request’.

How can we set the State correctly when using the API?

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [August 6, 2015, 9:30am UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/3 "2015-08-06T09:30:17Z")

</div>

I was able to create a new field with state filled in via [API Tester](https://github.com/mautic/api-library). There must be another problem with your API call.  
 ![](http://drive.google.com/uc?export=download&id=0B0VKZ9KdWYKnbDBkRXp2dTBBS2s)

---

<div class="post-metadata">

**Author:** ![dima](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dima](https://forum.mautic.org/u/dima)\
**Post date:** [August 8, 2015, 9:58am UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/4 "2015-08-08T09:58:57Z")

</div>

@escopecz Are you sure, that this lead’s state is California now? If you check the response, you will see error in state field, but lead will be added. If you check lead on UI, you won’t see lead’s state, it will be empty. So I’m not sure that the question may be closed.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [August 9, 2015, 10:30am UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/5 "2015-08-09T10:30:52Z")

</div>

Yes, I’m sure. Here is how the lead looks like in the Leads table and when I see the edit form, I can see the state selected.  
 ![](https://drive.google.com/uc?export=download&id=0B0VKZ9KdWYKnakkzVUxscUVTWDA)

---

<div class="post-metadata">

**Author:** ![dima](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dima](https://forum.mautic.org/u/dima)\
**Post date:** [August 9, 2015, 1:21pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/6 "2015-08-09T13:21:33Z")

</div>

Thanks for reply. Could you please paste the exact request from api tester(using Fiddler or so), so I can see how this filed was passed? Look like I send the state field in some another format than yours.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [August 9, 2015, 1:41pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/7 "2015-08-09T13:41:27Z")

</div>

You can use the API tester linked in my first post as well which I think is better option than to use me as an intermediate. There is more debug info you can find helpful. Follow these steps:

1. `cd /var/www/html` (or whatever you use for your local development)
2. 

```auto
git clone git@github.com:mautic/api-library.git
```

3. Go to [http://localhost/api-library/apitester/index.php](http://localhost/api-library/apitester/index.php) (or whenever it got cloned)
4. Create Mautic API credentials with callback to `http://localhost/api-library/apitester/index.php`
5. Fill in the local Mautic URL
6. Press Submit button (the URL get saved to the session)
7. Insert oAuth keys created in step 4.
8. Fill in the API endpoint you want to use. In your case it is `leads/new`
9. Change HTTP method from GET to POST (which is required for this endpoint.
10. Create some Parameters to create a lead with. You can use similar like in my first image.
11. Submit and view the response

---

<div class="post-metadata">

**Author:** ![dima](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dima](https://forum.mautic.org/u/dima)\
**Post date:** [August 13, 2015, 5:53pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/8 "2015-08-13T17:53:55Z")

</div>

Well, it’s not so easy to launch api tester on Win PC for .Net engineer 🙂 After few hours I managed to run php local server to host api tester. But now it fails with error

[code]Warning: require(F:api-library-masterapi-library-master/vendor/autoload.php): failed to open stream: No such file or directory in F:api-library-masterapi-library-masterapitesterindex.php on line 5

Fatal error: require(): Failed opening required ‘F:api-library-masterapi-library-master/vendor/autoload.php’ (include\_path=’.;C:phppear’) in F:api-library-masterapi-library-masterapitesterindex.php on line 5[/code]

I tried to install Composer, but no luck:( So it would be really great if you can just show the request which contains state field.

Thanks

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [August 21, 2015, 6:50am UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/9 "2015-08-21T06:50:21Z")

</div>

Here’s the full log  
 ![](https://drive.google.com/uc?id=0B0VKZ9KdWYKnTlZMampOOUsyOHc)

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:58pm UTC](https://forum.mautic.org/t/create-lead-on-api-state-field-produces-error/2139/10 "2020-02-02T22:58:42Z")

</div>


