Bit.ly bitlink creation always return forbidden even after email verification? - http

I have registered and done email verification. Then, I try the most baisc API trying to shorten a testing link. The following is my HTTP packet.
POST /v4/shorten HTTP/1.1
Host: api-ssl.bitly.com
Content-Type: application/json
Authorization: Bearer my-generic-access-token
Cache-Control: no-cache
{
"group_guid": "shorten_link_testing",
"domain": "mytesting.site.com",
"long_url": "http://mytesting.site.com/"
}
And the following is the return from bit.ly:
{
"message": "FORBIDDEN",
"resource": "bitlinks",
"description": "You are currently forbidden to access this resource."
}
I am using Postman to test, so I am quite sure it is not the problem of my code. And the message format meets that in the documentation of bit.ly, so at least the connection is success. As far as I know, bit.ly should have 10,000 quota for free shorten link per month for every account, right? What have I missed so that I am banned from the shorten link service?

The group_guid param needs to reference the id of a group associated with your bitly account. Hit this api endpoint with your generic access token to get a list of the groups/guids bitly has associated with your account:
GET https://api-ssl.bitly.com/v4/groups.
Apparently the domain param is optional, because your account may have a default domain associated with it. It worked for me after removing the domain param altogether.
https://groups.google.com/forum/#!topic/bitly-api/9RywN3ETLkg
Hope this helps!!

I have been looking around for these issues. Currently, my solution is by removing body group_guid and getting a response 201 (created). I hope my information helps.

Related

LinkedIn Posts API returns INTERNAL_SERVER_ERROR

Running into an issue when trying to call the Posts API.
I'm getting a list of the authenticated user's posts through https://api.linkedin.com/rest/posts?q=author&author=AUTHOR_URN (https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api?view=li-lms-2022-07&tabs=http#find-posts-by-authors) which worked yesterday but not anymore today.
I am convinced I changed something between then and now, but whatever I do I cannot seem to get the request to work anymore.
The error returned does not give me a lot of information either:
{
"message": "Internal Server Error",
"status": 500,
"code": "INTERNAL_SERVER_ERROR"
}
I also created a request to fetch images yesterday, which does still work:
https://api.linkedin.com/rest/images/ids=List(IMAGE_URN) (https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2022-07&tabs=http#batch-get-images)
URN I'm using for the /posts request is formatted as follows: urn%3Ali%3Aorganization%3A<REDACTED> (where <REDACTED> is the numeric author identifier).
Confirmed the headers are the same between the /posts request and /images request.
Headers for reference:
Authorization: Bearer ACCESS_TOKEN_REDACTED
X-Restli-Protocol-version: 2.0.0
LinkedIn-Version: 202207
Is there anything I'm missing here that I need to get my /posts request working?
Thanks in advance!
Talked to someone from LinkedIn support since the issue occurred for me. Their response:
It's possible that you were getting that error due to a small hiccup on our side at that time - This can happen when we deploy updates or fixes.
Since then I've not seen this happen anymore, so expecting this is the case. Closing as answered.

HERE.com Places API, "ApiKey is missing" error message, but it isn't

I've tried the below request (with two different proper API keys), on the HERE Places API, but I get an auth error.
Request:
https://places.sit.ls.hereapi.com/places/v1/autosuggest
?at=40.74917,-73.98529
&q=chrysler
&apiKey=g51V9*****N4-_GTA
Response:
401
{
"error": "Unauthorized",
"error_description": "ApiKey is missing."
}
I've also tried OAuth, I can get the request token, but when I use this for the places request I get an HTML webpage (for HERE place API) as the response, rather than an expected JSON or XML reponse.
Is anyone able to get any of the example requests to work for Places API?
I had this issue before aswell. Trying the exact same request as you, in Postman with my own apiKey, made the request successfull.
Try making the URL a single line, there might be newline characters hidden somewhere.
This has solved this issue for me many times using this API.
Example:
https://places.sit.ls.hereapi.com/places/v1/autosuggest?at=40.74917,-73.98529&q=chrysler&apiKey=g51V9*****N4-_GTA
You need to check the key name it may wrong
you should check it out into the documentation of api. and see key name
try key name apikey or api_key or api-key instead of apiKey
https://places.sit.ls.hereapi.com/places/v1/autosuggest
?at=40.74917,-73.98529
&q=chrysler
&apikey=g51V9*****N4-_GTA
Please refer to this guide for the updated list of domains to use with apiKey.
For places, the domain is: places.ls.hereapi.com
Disclosure: I'm a product manager at HERE Technologies
In my case I was using : https://github.com/julianshen/gin-limiter with the provided example

invalid_grant error when attempting oAuth2 for Box API

I have been attempting to get access tokens for the Box API and am running into a persistent problem. I am following the steps listed on this page. I am able to do the first leg and get a security token from a request to
https://account.box.com/api/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&state=security_token%3DKnhMJatFipTAnM0nHlZA
I am then doing a POST request to
https://www.box.com/api/oauth2/token?grant_type=authorization_code&code={CODE_FROM_PREVIOUS_REQUEST}&client_id{MY_CLIENT_ID}&client_secret={MY_CLIENT_SECRET}
I also am including the header
Content-Type: application/x-www-form-urlencoded
With all this I am getting back:
{
"error": "invalid_request",
"error_description": "Invalid grant_type parameter or parameter missing"
}
Is there something I am missing here? Thank you in advance, any help would be appreciated
You're not actually POST-ing the parameters since you've included them in the URL as query parameters. You should pass the parameters as part of the HTTP request body.

AWS API Gateway: Add header if response is Unauthorized

I setup an API Gateway in AWS that uses custom authorizers to implement an OAuth2 flow. It works fine. When the user is not authorized they get a 401 Authorized response. That is correct as well, but I would like to add a header that gives the client the endpoint where it can get the token. Something like AuthorizeUrl: url
How can I add this header to my response?
Unfortunately this isn't possible but it's on our backlog. I know it doesn't really make sense when the client gets a 401 but you can't tell them how to authorize.
I don't have an ETA to provide but I'll add a +1 to the feature request.
AWS added this functionality last year.
Refer to this
To do it manually:
Go to 'Response Headers' in API Gateway Console.
Choose Unauthorized (401)
Below 'Response Headers' add AuthorizeUrl and url
Save and deploy API to some stage.
To add this to Cloudformation, refer to this similar answer.
You can also add this to swagger, by adding this snippet(yaml):
x-amazon-apigateway-gateway-responses:
UNAUTHORIZED:
statusCode: 401
responseParameters:
gatewayresponse.header.AuthorizeUrl:"url"
responseTemplates:
application/json: "{\"message\":$context.error.messageString}"
In the API Gateway console go to the "Method Response" interface. You can add HTTP Status 401. In "Response Headers" add your custom "AuthorizeUrl" header. Then in the "Integration Response" interface you can add the value you'd like for that header.

Marketo REST API token keeps expiring

I followed the Quick Start Guide on Marketo's site for their REST API. This went well. I was able to get a successful response from their website.
Request:
curl https://ABC-DEF-123.mktorest.com/rest/v1/lists.json?access_token=123:ab
Response:
{"requestId":"123#abcf7aff","result":[],"success":true}
However, when I tried the same request the next day, I received:
{"requestId":"123#abc6731ab6f","success":false,"errors":[{"code":"601","message":"Access token invalid"}]}
I logged into the Marketo admin and noticed that the token I copied and pasted out of the dialog box was different. I tried this new one and it worked.
(This is taken from the guide)
I came across another guide on their site that describes a different authentication process. Marketo Authentication Guide
This guide mentions the token that is returned from the API endpoint has an expiration so I suspect that all Marketo tokens expire (or I need to disable this). However, I have not been able to successfully make requests to this endpoint with my client ID and client secret.
Request:
curl https://ABC-DEF-123.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id=ACLIENTID&client_secret=ACLIENTSECRET
Response:
{"error":"unauthorized","error_description":"An Authentication object was not found in the SecurityContext"}
Any help in the right direction would be appreciated. Thanks in advance.
REST API tokens expire. So you typically will need to request a token for each session.
from your specific installed URL, like: MARKETOURL/identity/oauth/tokengrant_type=client_credentials&client_id=abc&client_secret=xyz
Which will result in (example):
{
"access_token": "1234",
"token_type": "bearer",
"expires_in": 3599,
"scope": "email#email.com"
}
You will need to start out your sessions with this request to do subsequent calls. I have code that runs this first and then requests a new token if it expires. The expires_in field is in seconds.
Source: http://developers.marketo.com/documentation/rest/authentication/
I was not able to figure out why my curl requests were failing, but I was able to successfully call the Marketo API with mrkt, a Ruby Gem for Marketo.
I've looked through the logs of what the gem is generating for requests and they appear to be exactly the same. But at least I now successfully calling Marketo.
You need to use following sequences.
grant_type= client_credentials
client_id =you will get Marketo admin where you generate token
client_secret=you will get Marketo admin where you generate token
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
GET <Identity URL>/oauth/token?grant_type=client_credentials&client_id=<Client Id>&client_secret=<Client Secret>
Your first call failed because your token expires every hour currently, according to Marketo's docs.
Your curl call to get a new token failed because curl (or something) was stripping off the auth arguments. Try wrapping the url in quotes.
curl "https://ABC-DEF-123.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id=ACLIENTID&client_secret=ACLIENTSECRET"
You can get more information about what curl is sending with the -v flag. Running this would have given you enough information to at least know that your entire url wasn't being passed down to the request.
curl -v https://ABC-DEF-123.mktorest.com/identity/oauth/token?grant_type=client_credentials&client_id=ACLIENTID&client_secret=ACLIENTSECRET

Resources