Skip to Main Content

General Cloud Infrastructure

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Use Oracle Cloud Infrastructure Email Delivery in Rest API and PHP Programming format

user-bwaq8Jun 1 2023 — edited Jun 2 2023

I want to use Oracle Cloud Infrastructure Email Delivery REST API and create a domain name. But I am having trouble in making authorization and header. There is no clear instruction how to use authorization and header in Oracle Cloud Infrastructure REST API Web Page specially when I browse email delivery. https://docs.oracle.com/en-us/iaas/api/#/en/emaildelivery/20170907/EmailDomain/CreateEmailDomain

I tried to use a PHP programming code to achieve what want but I still receive an error. Here is my PHP code

   $Url = 'https://ctrl.email.il-jerusalem-1.oci.oraclecloud.com/20170907/emailDomains';
   $ClientId = 'MyOracleCloudUsername'; $Secret = 'MyOracleCloudPassword';
   $AuthorizationHeader = 'Basic ' . base64_encode($ClientId . ':' . $Secret);
   $Data = []; $Data['compartmentId'] = 'MyCompartmentId'; $Data['name'] = 'MyEmailDomain'; $Data = json_encode($Data);
   $Header = (array("Accept: application/json","Content-Type: application/json", "Authorization: " . $AuthorizationHeader));
   $Options = array('http' => array('header' => $Header, 'method' => 'POST', 'content' => $Data, 'ignore_errors' => true ));
   $Context  = stream_context_create($Options);
   $Res = file_get_contents($Url, false, $Context);
   echo $http_response_header[0] . '<br><br>' . $Res; exit;

Here is the error message:

HTTP/1.1 401 Unauthorized

{ "code" : "NotAuthenticated", "message" : "The required information to complete authentication was not provided or was incorrect." }

Comments
Post Details
Added on Jun 1 2023
1 comment
587 views