Xero - Attach a file to an existing invoice using Attachment API - laravel

Documentation => Attachment API.
Although access_token is correct, whenever I upload a file, I always got 401 error(unauthorized).
pls, explain with an example of your request, including request headers?
My request header is:
xero-tenant-id: tenant_id
Authorization: Bearer access_token
Content-Type: image/png
Content-Length: 1000
Thanks.

Attachments require different scopes to use.
Have you included the 'accounting.attachments' scope in the scopes requested when authorising the connection?
Copied from: XERO PHP SDK - Createinvoiceattachment throws 401 Unauthorized error
it worked to me

Related

Using Rest API to run Oracle BI Publisher report (12.2.1.2)

I am trying to run BIP report using REST API using commands as detailed in below link provided by Oracle. I am providing the parameters as below. However the request fails with error 400-Bad Request.
Oracle Link:
https://docs.oracle.com/middleware/12211/bip/BIPAP/op-v1-reports-%7BreportPath%7D-run-post.html
I also followed the instruction on below link. But for me it is not working.
Unable to use the REST API services in Oracle Business Intelligence Publisher 12.2.1.2.0 server
My request details:
URL: http://localhost:port/xmlpserver/services/rest/v1/reports/Publish%2FSTLMTP_I_C_0594_PIIC_RESTAPI/run
Method: POST
Header: Content-Type: multipart/form-data boundary: "Boundary_1_1153447573_1465550731355" Accept: multipart/form-data Authorization: Basic username:Password (encoded)
Body: (Selected option raw-text. Also tried as raw-XML/JSON/HTML)
--Boundary_1_1153447573_1465550731355 Content-Type: application/json Content-Disposition: form-data; name="ReportRequest"
{"byPassCache":true,"flattenXML":false,"attributeFormat":"pdf"}
--Boundary_1_1153447573_1465550731355--
400 is bad request.
parameter that you send in ReportRequest have problem.
please check JSON file .
if you have postman check on this.
If your problem is not solved, tell me to send a photo

How to send POST request to secure Laravel API route from Postman

I am having problems in submitting POST request to secured Laravel API routes via Postman. My GET requests work fine, but my POST cant go through the security even though I have provided an api token.
So my question is: How properly to send POST request to secured Laravel API routes from Postman?
Add this is the request header.
[enter image description here][1]accept: application/json
content-type: application/json
authorization: "your_token"
Found the solution:
Set your Authorization to API Key:
Next, in headers section you need to add X-Requested-With field:

How to get an access token from Google without an api library?

I am working on an Elixir Phoenix web project where I want to interact with Google's Indexing API.
Google uses OAuth2 to authenticate api requests and actually has a decent documentation on this.
But it only explains the process using one of the supported libraries in Python, Java, PHP or JS.
I would like to make the HTTP requests by myself to retrieve that access token. But the request format (including headers or parameters) is nowhere documented and I cannot even figure out from the libraries' source code.
I have tried requesting https://accounts.google.com/o/oauth2/token (also other eligible URLs) in Postman with the "OAuth 2.0" request type.
But it was all just guessing and trying. All the research did not help.
There are useful instructions including HTTP/Rest examples at Using OAuth 2.0 for Web Server Applications. Each step has the individual parameters fully documented. Here are some useful excerpts.
Send user to Google's OAuth 2.0 server. Example URL:
https://accounts.google.com/o/oauth2/v2/auth?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&
access_type=offline&
include_granted_scopes=true&
state=state_parameter_passthrough_value&
redirect_uri=http%3A%2F%2Foauth2.example.com%2Fcallback&
response_type=code&
client_id=client_id
Retreive authorization code (your domain). Example:
https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
Request access token. Example:
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id=your_client_id&
client_secret=your_client_secret&
redirect_uri=https://oauth2.example.com/code&
grant_type=authorization_code
Use API. Example:
GET /drive/v2/files HTTP/1.1
Authorization: Bearer <access_token>
Host: www.googleapis.com/

How do I send a Google API POST request using Jmeter?

I have never used Jmeter before. I have been trying to use Jmeter to send an HTTP request to Google Vision API - but it's returning a FORBIDDEN (403) error. My request as well as required response is in JSON format.
I have attached below the:
a) HTTP Request
b) Response Error
Other than this, in HTTP Header Manager I have set:
Content-Type: application/json
What is wrong with the attached request?
Request image..
Response error image
According to Authenticating to the Cloud Vision API article you might require to provide OAuth token, it can be done via HTTP Header Manager like:
Name: Authorization
Value: Bearer YOUR_ACCESS_TOKEN
See How to Run Performance Tests on OAuth Secured Apps with JMeter article for more details on interacting with OAuth-protected web applications in JMeter tests.

How to develop test-automation using Postman when OAuth 2.0 authorization is required

I have an ASP.NET Web API 2 which is using OAuth 2.0 for authorization. And let's imagine I have a simple Web API method, like:
GET: http://host/api/profiles/user123 (requires OAuth 2.0 token)
So, with Postman, it is easy to test this Web API. I get an OAuth token for user123 from the Web API OAuthAuthorization method and then I use that token in the header of the HTTP request:
GET /api/profiles/user123 HTTP/1.1
Host: {host}
Authorization: Bearer {Token}
Content-Type: application/json
Cache-Control: no-cache
However, if I save my test and run it later (either by Postman itself or by Newman), the token will be expired at that time and it won't work.
How can I make Newman to get a new token automatically for user123 and use it in the HTTP request?
Note: I know how to use Postman's Authentication helpers to ask for a new token. But this scenario doesn't fit the test-automation. In test-automation, I want to remove any human interaction.
It's simple, get your access token at run time and save it into environment variable. Then use it in your next Get request.
In Get Token request, do this in Tests sections:
var body = JSON.parse(responseBody);
pm.environment.set('AccessToken', body.access_token);
In your main Get request, you can use the environment variable in Authorization header:
Authorization: Bearer {{AccessToken}}
Hope this helps.

Resources