Gravity Forms API always 401

2019-05-10 05:48发布

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.

4条回答
【Aperson】
2楼-- · 2019-05-10 06:01

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-05-10 06:09

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.

查看更多
淡お忘
4楼-- · 2019-05-10 06:13

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

查看更多
戒情不戒烟
5楼-- · 2019-05-10 06:20

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.

查看更多
登录 后发表回答