Gravity Forms API always 401
Asked Answered
S

4

5

I am trying to use the gravity forms rest api, https://www.gravityhelp.com/documentation/article/web-api/ but I receive a 401 error no matter what I try. I've tried using all the methods listed in the documentation and in Steven Henty's article, https://www.stevenhenty.com/gravity-forms-api/ but it doesn't seem to work.

If I am logged into a wordpress site as administrator should I not be able to use a link like:

http://mydomain/gravityformsapi/forms/

Thank you for any suggestions.

Smallclothes answered 12/8, 2016 at 20:5 Comment(0)
M
5

For mine case it was that I haven't clicked the update button "Web API" Tab.

Make sure you click update button , although it does show the API Key's but still you have to click update button to enable API.

Morrell answered 6/8, 2017 at 19:32 Comment(3)
Thank you for this, had me stumped for a while! To summarise for anyone else, after you have checked the 'Enabled' checkbox to enable access to the API in the Gravity Forms API Settings and clicked the 'Update' button, you need to click the 'Update' button AGAIN once the API credentials have been generated. Not logical I know but seems to be the answer!Bundle
Same problem here. It's not obvious at all that you have click to update again, but this solved it.Citizenry
Since it's not as obvious as it should be, the api v1 "Show/Hide QR Code" button only appears if the rest api enabling has been successfulGrimaldi
V
2

I was getting the same thing due to some weirdness about the route endpoint. When calculating the signature you don't use a trailing slash on the route: forms/1.

But you do use a trailing slash in the URL (otherwise I got a 301 Moved Permanently):

http://demo.gravityforms.com/gravityformsapi/the_route/?api_key...

It looks odd to have /?api_key... but that is what works for me.

Here's the ruby example I was using with the demo credentials:

GravityFormsAPI.generate_URL(site: 'demo.gravityforms.com', route: 'forms/1', public_api_key: '5b225f8382', private_api_key: 'fc6d1bc71d2ebfc')

Hope this helps.

Viewless answered 21/8, 2016 at 15:58 Comment(1)
If I want to add feild_filters or get a single entry by entry_Id it always give 401 no matter what I do. If I use is with / it's the same it I use without it it's the same. Although browser automatically adds / at the end of URL. I'm trying to implement it on iOS and I followed github.com/ibjects/GFAPI-iOSRepublic
O
1

Sometimes i received intermittent 401 error after a lot of research i find this article

Azure DocumentDB Intermittent 401 error when querying REST API via Obj-c

If the signature contains + sign i received 401 error

Maybe that help other person

Sorry for my english writing

Ourselves answered 18/11, 2016 at 18:30 Comment(0)
R
0

Based on the solution here I'm posting this answer.
Imagine you have created the URL and it didn't work and you got 401. Then after a little time you realized the error that Opps! The parameters I was passing needed a bracket and you run the code again and you again got 401. Why is that?

This is because the parameters which are apiKey, Signature and Expire time are the same and you only changed the other parameters with your GET request. However these three parameters are used to authenticate the user so that means the old signature which was generated to deny the permission will deny it again no matter what.

So to fix that I just changed the expire time from 1577922200 to 1577933200. I could've changed it to anything but the thing is I just need to give something new so that a new signature can be generated. So when I changed it started working.

OTHER POSSIBLE REASON

While making the signature using SHA1 you use NSString *string_to_sign = [NSString stringWithFormat:@"%@:%@:%@:%@",api_key,http_method,route,expires]; as per the documentation. But in order to make CCHmac you have to pass it two things:

  1. Key
  2. Data

and based on the link it is created as

const char *cKey  = [api_private_key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [string_to_sign cStringUsingEncoding:NSASCIIStringEncoding]; 

So what I was mistaking is that I was using API Key in cKey instead of API Private Key. So I change it as per tutorial said and it worked. Otherwise I was getting 401 not matter what I try.

Republic answered 1/9, 2016 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.