Azure DevOps API using PATs returns HTML in my PHP curl call, Postman returns Json - php-curl

Trying to use the Azure APIs to build a web app that returns data from Azure Devops.
here is the API I'm calling: https://dev.azure.com/{{organization-pica}}/{{project}}/_apis/test/Plans/14/suites/15/testcases?api-version=5.0
POSTMAN: using basic authentication this works well and returns json result.
When I call this from PHP cURL it returns HTML?
Any help would be appreciated.

Using the wrong URL. https://dev.azure.com/{{organization-pica}}/{{project}}/_apis/test/Plans/4/suites/6?$expand={$expand}&api-version=5.0

Related

How to add security to Azure Function?

I’m new at Azure. So i’ve developed a simple Web app in net core 6 which autenticathes with AZ AD.
I also add to my solución an azure function but the idea is to add JWT to it .
From azure portal i added, authentication but i dont know how to get a token to , for example, test it with postman.
Does someone know how to do this? I’ve Watch a lot of videos but still can’t get it .
Regards
i need help to add security to my az function and be able to add jwt to my web app and to try tokens from postman.
I tried to reproduce the same in my environment and got the results like below:
Create an Azure AD Application and add API permissions:
Generate the Auth-Code by using below Endpoint:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/authorize?
client_id=ClientID
&response_type=code
&redirect_uri=RedirectURI
&response_mode=query
&scope=[https://management.azure.com/.default](https://management.azure.com/.default "https://management.azure.com/.default")
&state=12345
To generate the token, I used the below parameters:
GET https://login.microsoftonline.com/TenantId/oauth2/v2.0/token 
client_id:ClientID
client_secret:ClientSecret
scope:https://management.azure.com/.default
grant_type:authorization_code
redirect_uri:RedirectUri
code:code
By using the above generated access token, you can access Azure Function successfully like below:
GET https://management.azure.com/subscriptions/SubID/resourceGroups/RG/providers/Microsoft.Web/sites/funcapp/functions/function?api-version=2022-03-01

How to store and respond with variables for API request

I am attempting to create a dynamic responsive server which is able to:
read a request
store the token in an environment variable
use that environment variable in the response back to the source
I am unsure where to begin with this, I have had a look at some API tools such as PostMan and Insomnia but although I can set up a mock server which would receive the responses, the data I want to save is not being stored in the variable and thus is not being used in the response.
Some guidance would be appreciated.
Thank you
What language and platform you are using?
If you are using any of the major public cloud options, (AWS, Google, Azure), there are easy to deploy API Gateway Services that required minimal code to get started and supports environment variables.
If you are using a local development only,
then you can get started with ASP .NET Core Web API: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio
Then use environment variable:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1
Or instead once you setup your API running locally, you can use Postman variables:
https://learning.postman.com/docs/sending-requests/variables/

Attempting to connect to Oro 4.1.1 Web API via the OAuth

I am trying to utilize the OroCommerce Web API which was introduced to interact with my clients.
The first step of oauth2-token seems to be working well, but he consequent requests to the api's such as customers GET, customerusers GET etc all end up with 401-Unauthorized Error.
I am trying to test the whole flow through the POSTMAN.
I have checked the Web API access is enabled and also verified that the guest users are enabled.
What's strange is the the /api/doc seems to be working well, but when I try to mimic the same via POSTMAN, it always ends up with 401 -Unauthorized Access.
Any idea why it could be failing?
Make sure you included Content-Type and Bearer prefixed Authorization headers in the request built using POSTMAN. Like explained in the OroCommerce documentation.
The authentication with Bearer header also explained in POSTMAN documentation.

Invoking wso2greg Artifcat Rest API via wso2api manager is not working - any ideas to fix

UPDATED QUESTION to clarify more.
I have two servers : wso2greg containing custom artefacts and wso2am (api manager).
The gouvernance register is intended to be used internally (intranet) and some of it's feature are intended to be exposed externally and acceded via it's rest API.
In order to manage wso2greg API accesss, we used an wso2am (api manager) server, where we did define an API that act as a proxy for the wso2greg API.
In our experiments, we found the strange behaviour described below :
Successfully direct calling wso2greg artefact rest api (the exact url is
https://localhost:9443/resource/1.0.0/artifact/_system/governance/myartifact/art1 and i'm following the documentation of this REST API from here https://docs.wso2.com/display/Governance520/Resources+with+REST+API ) using postman. The API reacts as described in the documentation.
Error 500, reported on wso2greg server, when calling the same REST API, but via API manager (using publisher application).
So as a summary :
Directly calling wso2greg rest API woks fine and a got results back
Adding this working API, in wso2am and than calling it gives always error 500.
As extra information:
Tested with other wso2greg REST API , such as "rating" or "comments" and I was able to call it successfully either directly or throw Api manager.
Tried to get information related to default wso2greg artifacts such as restservice, but i got exactly the same pb when (error 500) interagting with API manager.
Working with the last version of both products : wso2greg version 5.2.0 and wso2am version 1.10.0
Please advice, or clarify how could i debug this internal error in wso2greg.
Regards,
I hope your not using G-Reg + APIM feature installed version. I presume your using separate G-reg 5.2.0 and APIM x.x.x. Since your using the second option you can't use G-Reg REST API with APIM, therefore you have to use APIM REST API instead.
Get an API
Description: Get details of a specific API.
URI: http://localhost:9763/publisher/site/blocks/listing/ajax/item-list.jag
URI Parameters: action=getAPI&name=xxx&version=xxx&provider=xxx
HTTP Methods: POST
Example:
curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/listing/ajax/item-list.jag -d "action=getAPI&name=PhoneVerification&version=1.0.0&provider=admin"
Please follow this link to see all the api usage.
Thanks #thusharaK for providing help.
The solution was to add Message Mediation Policies which forces json header on output.
Now i got my correct response from API manager (in fact, i got a binary response in test console and a json response in postman) .

import.io curl simple data integration

I want to get the simple api integration from https://import.io via curl. I created a magic api and struggle now to get the data.
Do I use the magic api on the browser, it works fine. But with curl I get a {"code":"NOT_AUTHORIZED"}. Obvious that the authentication did not work.
Here's my code
#!/bin/bash
login=foo#bar.com
pass=foobar
userid=foo-bar
apikey=1f2o3o4b5a6r
curl --user $login:$pass https://api.import.io/store/data/033fbe66-13b7-4cf2-ba9c-58183a567a6f/_query?input/webpage/url=https%3A%2F%2Fwww.zalando.de%2Flp-ons-wom-sale-cat-v1%2F%3Forder%3Dsale&_user=$userid&_apikey=$apikey
What am I doing wrong? And how do I get it run with curl?
I could get it running. Found https://github.com/import-io/bashtractor/blob/master/bashtractor.sh which solved my problem.