# Gravity Forms API 2 JavaScript authentication problems

**URL:** <https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802>\
**Category:** Get Help\
**Tags:** custom, api, authentication\
**Created:** [September 21, 2019, 7:40pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802 "2019-09-21T19:40:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![coxc02](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@coxc02](https://community.gravityforms.com/u/coxc02)\
**Post date:** [September 21, 2019, 7:40pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/1 "2019-09-21T19:40:12Z")

</div>

I am new to Gravity Forms and WordPress. I am using Gravity Forms (version 2.4.12) in my WordPress site (WP version 5.2.3). I feel comfortable with JavaScript, so I am trying to use JS to read in my GF form entries and display them in an HTML table that I will make searchable. I am trying to follow Gravity Forms documentation on using Basic Auth and OAuth 1.0a. I am unable to get Basic Auth to work but I am able to get OAuth 1.0a to work in Postman.

I have not been successful using Postman and following the Basic Authentication example **[here](https://docs.gravityforms.com/rest-api-v2/#basic-authentication)**. With Basic Authentication, I provide my consumer key (username) and consumer secret (password) and I get the following error. I am not sure why this Basic Auth example is not working.

```
Request made to: https://mysite.com/wp-json/gf/v2/forms/4/entries

Result: 

{
"code": "rest_forbidden",
"message": "Sorry, you are not allowed to do that.",
"data": {
    "status": 401
}

```

I am able to use Postman and follow the OAuth 1.0a Authentication example as shown **[here](https://docs.gravityforms.com/rest-api-v2/#oauth-1-0a-authentication)**. This is working fine with Postman. At this point, I cannot get Basic Auth to work, but I can get OAuth 1.0a to work in Postman only.

Since I can get Postman working with OAuth 1.0a, I figure why not generate the JavaScript Postman is using to get this working in my WordPress site. What I am seeing is that Postman is generating some of the fields I need to figure out how to recreate within my JavaScript. I am not sure what all I need. I can see Postman using my consumer key, but it does not appear to be using my consumer secret for OAuth 1.0a in its generated JS output.

```
// These three params I know.
oauth_consumer_key = ck_1234....321a
oauth_signature_method = HMAC-SHA1
oauth_version = 1.0

// I need help creating these params as Postman generates these for each request.
oauth_timestamp = this I can create               
oauth_nonce = I am not sure how to create this
oauth_signature = I am not sure how to create this

```

I am looking for help on how to create the last three params, assuming that is all I need to request a response from my GF endpoint. This is my endpoint.

```
https://mysite.com/wp-json/gf/v2/forms/4

```

To create the timestamp, I have this.

```
var d = new Date;
var expiration = 3600; // 1 hour,
var unixtime = parseInt(d.getTime() / 1000);
var future_unixtime = unixtime + expiration;

// future_unixtime is my timestamp, example = 1569094276

```

To create the oauth\_nonce, I am doing this. I am thinking this is an 11 character string based on what Postman is creating each time I make a request and get back results successfully. It is always an 11 character string.

```
function createRandomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for(var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    return text;
}

// generate the nonce
var nonce = createRandomString(11);

```

Lastly, I have no idea how to create the oauth\_signature. In Postman, following the GF example for OAuth 1.0a, I can see that the consumer key and consumer secret are populated, but access token and token secret are not. Do I just leave those as empty strings?

I am using WordPress and I am new to WP. I can reference JS libraries via script tags in my HTML head, but I am not sure what other libraries I can use. It would be awesome to just do something like this.

```
var signature = CryptoJS.HmacSHA1(some_string, oauth_consumer_key + '&' + oauth_consumer_secret);

```

I am not sure what to do for this signature.

1. Why won’t Basic Auth work for me?
2. What do I need to recreate in JavaScript in order to get OAuth 1.0a to work?

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![user5dc5eaa4bda86851](https://avatars.discourse-cdn.com/v4/letter/u/aca169/32.png) [@user5dc5eaa4bda86851](https://community.gravityforms.com/u/user5dc5eaa4bda86851)\
**Post date:** [November 9, 2019, 10:58am UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/2 "2019-11-09T10:58:00Z")

</div>

I am having the exact same problem! Did you solve?

---

<div class="post-metadata">

**Author:** ![dannyb](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dannyb](https://community.gravityforms.com/u/dannyb)\
**Post date:** [February 11, 2020, 12:04am UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/3 "2020-02-11T00:04:12Z")

</div>

I have the same issues. Would like to hear from the GF team on this.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 11, 2020, 1:59pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/4 "2020-02-11T13:59:59Z")

</div>

I recommend opening a support ticket if you’re having issues with the GFAPI v2 authentication. Thank you.

[https://www.gravityforms.com/open-support-ticket/](https://www.gravityforms.com/open-support-ticket/)

---

<div class="post-metadata">

**Author:** ![user5b13b577995466.6](https://avatars.discourse-cdn.com/v4/letter/u/c77e96/32.png) [@user5b13b577995466.6](https://community.gravityforms.com/u/user5b13b577995466.6)\
**Post date:** [June 14, 2020, 8:14pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/5 "2020-06-14T20:14:59Z")

</div>

Any solution? I am having the same problem. Can’t authenticate with basic auth in v1, can’t authenticate in v2 either with basic. Haven’t tried oauth in v2.  
Any advice ?

---

<div class="post-metadata">

**Author:** ![user5b13b577995466.6](https://avatars.discourse-cdn.com/v4/letter/u/c77e96/32.png) [@user5b13b577995466.6](https://community.gravityforms.com/u/user5b13b577995466.6)\
**Post date:** [June 14, 2020, 9:05pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/6 "2020-06-14T21:05:41Z")

</div>

Found the solution. See this page

> **[WordPress/application-passwords](https://github.com/WordPress/application-passwords/wiki/Basic-Authorization-Header----Missing)**
>
> Contribute to WordPress/application-passwords development by creating an account on GitHub.

I also had to move the Wordpress block to the top of my htaccess, and leave this plugin activated.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [June 15, 2020, 1:57pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/7 "2020-06-15T13:57:06Z")

</div>

Thank you for sharing that Adnaan.

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 5:11pm UTC](https://community.gravityforms.com/t/gravity-forms-api-2-javascript-authentication-problems/2802/8 "2022-01-04T17:11:33Z")

</div>


